...">

How to change the value of the Eval () field in a Gridview event to RowDataBound

I have a gridview:

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

The property Enabledis a boolean. Now I would like to display Enabled / Disabled based on True / False properties Enabled. 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 this will not work since the start of the event e.Row.Cells(3).Textis an empty string . How can I solve this problem? thank

+5
source share
2 answers
If e.Row.Cells(3).Text <> Boolean.FalseString Then
       e.Row.Cells(3).Text = "Enabled"
Else
       e.Row.Cells(3).Text = "Disabled"
End If
+4
source

Same problem with me.

e.Row.Cells[i].Textwas empty. I think the data is not connected at the time, which is somehow strange, since we are in the RowDataBound event.

However, I used:

     DataRowView drv = (DataRowView) e.Row.DataItem;
     if (drv["RNID"].ToString() == "")
     {
        e.Row.Visible = false;
     }

"RNID" - . .

+2

All Articles