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

标签 asp.net gridview rowdatabound

我有一个 GridView:

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

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

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 是一个空字符串。我怎么解决这个问题?谢谢

最佳答案

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

关于asp.net - 如何在 Gridview 中的 RowDataBound 事件中更改 Eval() 字段的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11671905/

相关文章:

.net - 将字符串解析为整数(无论 hell 还是高水位)

asp.net - 使用 GridView.RowDataBound 事件显示特定行

ASP.net Gridview 突出显示多列中的最大值

c# - 插入数据库后在 gridview asp.net C# 的模板字段中隐藏下拉列表

c# - 如何控制自动生成的字段 gridview 的列数

c# - ASP.NET 从远程共享发送 PDF 文件给用户打开

c# - 实现自定义 CacheDependency 以使 ASP.Net 缓存项无效

c# - Gridview 的 Jquery 和更新面板不起作用

c# - ASP.NET gridview 行 onclick

c# - 使用 EmptyDataTemplate 时如何删除 ASP.NET GridView 中的空行?