If Statement in ASP.NET Gridview "ShowEditButton"

2.7k views Asked by At

I have a question for you regarding ASP.NET's GridView and performing an If Statement when it comes to the commandfield for the "Edit" button.

Here is the code I have right now:

 <Columns>

       <% if (Eval("Session("auditUpdate")") == true) { %>
            <asp:CommandField ShowEditButton="True" />
        <% } %>

        <asp:BoundField DataField="MODEL_NUMBER" HeaderText="MODEL_NUMBER" 
            ReadOnly="True" SortExpression="MODEL_NUMBER" />
 </Columns>

I have a session boolean variable named auditUpdate that I am updating in the "OnRowDataBound" event for the GridView. I want to show the edit button if 'auditUpdate' == true otherwise not show it at all.

I have searched all over and scoured my ASP.net book but I cannot seem to find the answer.

Thanks!

1

There are 1 answers

1
Jupaol On BEST ANSWER

You could try to set the visibility in code

if(this.auditUpdate)
{
   this.GridView1.Columns[0].Visible = true;
}