title: Displaying Edit button in GridView based on Role
body: <p>I have a Grid View. I added <code>AutoGenerateEditButton=True</code>.</p>
  
  <p>I want to display that button to users that belong to a certain role. If not the button is not rendered.</p>
  
  <p>What do you recommend? Which event do I have to handle to accomplish that purpose?</p>
  
  <p>Do I have to work with template-driven control such as ListView?</p>
  
  <p><strong>Solution</strong>:</p>
  
  <pre><code>&lt;Columns&gt;
      &lt;asp:CommandField 
           ShowEditButton="True" /&gt;
      &lt;asp:BoundField 
           DataField="Id" 
           ReadOnly="true"  
           Visible="true" /&gt;         
      &lt;asp:BoundField 
           DataField="Title" 
           HeaderText="Title"  /&gt;         
  &lt;/Columns&gt; 
  </code></pre>
  
  <p>And the GridView's Load event:</p>
  
  <pre><code>if(!User.IsInRole("Manager"))
  {
      for (int i = 0; i &lt; grdMovies.Columns.Count; i++)
      {
          if (grdMovies.Columns[i] is CommandField)
          {
              grdMovies.Columns[i].Visible = false;
          }
      }
  }
  </code></pre>