Pergunta

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!

Foi útil?

Solução

You could try to set the visibility in code

if(this.auditUpdate)
{
   this.GridView1.Columns[0].Visible = true;
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top