如何在GridView改变RowDataBound事件的评估和演示的值()字段 [英] How to change in a Gridview on RowDataBound event the value of an Eval() field

查看:152
本文介绍了如何在GridView改变RowDataBound事件的评估和演示的值()字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个GridView:

 < ASP:GridView控件ID =gvDownloads>
   <柱体和GT;
      < ASP:的TemplateField的HeaderText =状态>
         <&ItemTemplate中GT;
             <%#的eval(已启用)%GT;
         < / ItemTemplate中>
      < / ASP:的TemplateField>
   < /专栏>
< ASP:GridView控件/>

已启用属性是一个布尔值。现在我想以真实显示启用/禁用/假的已启用属性。因此,我用:

 子gvDownloads_RowDataBound(BYVAL发件人为对象,BYVAL E上GridViewRowEventArgs)处理gvDownloads.RowDataBound        如果e.Row.RowType = DataControlRowType.DataRow然后            如果e.Row.Cells(3)。文本=真然后
                e.Row.Cells(3)。文本=启用
            其他
                e.Row.Cells(3)。文本=已禁用
            万一        万一结束小组

但是,当事件被启动,因为无法正常工作 e.Row.Cells(3)。文本是一个空字符串。我怎样才能解决这个问题?谢谢


解决方案

 如果e.Row.Cells(3)。文本<> Boolean.FalseString然后
       e.Row.Cells(3)。文本=启用
其他
       e.Row.Cells(3)。文本=已禁用
万一

I have a GridView:

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

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

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

这篇关于如何在GridView改变RowDataBound事件的评估和演示的值()字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆