本文介绍了如何在 RowDataBound 事件的 Gridview 中更改 Eval() 字段的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 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() 字段的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!