我有一个 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/