我有一个GridView:
<asp:GridView ID="gvDownloads">
<Columns>
<asp:TemplateField HeaderText="Status" >
<ItemTemplate>
<%# Eval("Enabled")%>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<asp:GridView/>
Enabled
属性是布尔值。现在,我想显示基于Enabled
属性的True/False的Enabled/Disabled。因此我使用:
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
我也有同样的问题。
e.Row.Cells[i].Text
为空。我认为数据当时没有绑定,这有点奇怪,因为我们在RowDataBound事件中。
然而,我使用了:
DataRowView drv = (DataRowView) e.Row.DataItem;
if (drv["RNID"].ToString() == "")
{
e.Row.Visible = false;
}
其中"RNID"
是我的应用程序中的列名之一。这解决了我的问题。