我有一个GridView:
<asp:GridView ID="gvDownloads">
<Columns>
<asp:TemplateField HeaderText="Status" >
<ItemTemplate>
<%# Eval("Enabled")%>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<asp:GridView/>
Enabled
属性是一个布尔型变量。现在我想根据Enabled
属性的真/假值来显示“已启用”或“已禁用”。因此,我使用以下代码:
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
是一个空字符串。我该如何解决这个问题?谢谢。