如何在 RowDataBound 事件的 Gridview 中更改 Eval() 字段的值

编程入门 行业动态 更新时间:2024-10-23 17:33:33
本文介绍了如何在 RowDataBound 事件的 Gridview 中更改 Eval() 字段的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我有一个 GridView:

I have a GridView:

<asp:GridView ID="gvDownloads">
   <Columns>
      <asp:TemplateField HeaderText="Status" >
         <ItemTemplate>
             <%# Eval("Enabled")%>
         </ItemTemplate>
      </asp:TemplateField>
   </Columns>
<asp:GridView/>

Enabled 属性是一个布尔值.现在我想根据 Enabled 属性的 True/False 显示启用/禁用.因此我使用:

The Enabled property is a boolean. Now I would like to display Enabled/Disabled based on True/False of the Enabled property. Therefore I use:

Sub gvDownloads_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles gvDownloads.RowDataBound

        If e.Row.RowType = DataControlRowType.DataRow Then

            If e.Row.Cells(3).Text = "True" Then
                e.Row.Cells(3).Text = "Enabled"
            Else
                e.Row.Cells(3).Text = "Disabled"
            End If

        End If

End Sub

但它不起作用,因为当事件启动时e.Row.Cells(3).Text 是一个空字符串.我怎么解决这个问题?谢谢

But it does not work since when the event is launched e.Row.Cells(3).Text is an empty string. How can I solve this problem? Thanks

推荐答案

If e.Row.Cells(3).Text <> Boolean.FalseString Then
       e.Row.Cells(3).Text = "Enabled"
Else
       e.Row.Cells(3).Text = "Disabled"
End If

这篇关于如何在 RowDataBound 事件的 Gridview 中更改 Eval() 字段的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-01 10:10:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/828268.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字段   事件   如何在   RowDataBound   Gridview

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!