title: How to hide a hyperlink control inside gridview through code behind inside page load?
body: <p>I have a  gridview on my web form. I have taken a hyperlink control inside the template field of gridview. I want that this hyperlink should be visible to only site admin. I have done this through <em>Gridview_RowDataBound</em> property. But instead of doing this I want to hide this hyperlink within page load.</p>
  
  <p>This is what I have done so far.</p>
  
  <p>aspx page-</p>
  
  <pre><code>&lt;asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="id" onrowdatabound="GridView1_RowDataBound1"
  BorderStyle="None" EnableModelValidation="True" ShowHeader="False" Width="1000px" GridLines="None"&gt;
  &lt;Columns&gt;
  &lt;asp:TemplateField&gt;
                  &lt;ItemTemplate&gt;
  &lt;asp:HyperLink ID="HyperLink2" runat="server" Font-Bold="True" Font-Size="Small" 
                          ForeColor="#FF3300" CommandName="EDT" CommandArgument="&lt;%# ((GridViewRow) Container).RowIndex %&gt;"
                          NavigateUrl='&lt;%# Eval("id","test1.aspx?id={0}") %&gt;'&gt;HyLink&lt;/asp:HyperLink&gt;
  &lt;/ItemTemplate&gt;
              &lt;/asp:TemplateField&gt;
  
  &lt;/Columns&gt;
  &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>cs page-</p>
  
  <pre><code>protected void GridView1_RowDataBound1(object sender, GridViewRowEventArgs e)
      {
          if (e.Row.RowType == DataControlRowType.DataRow)
          {
              if (Convert.ToString(Session["logname"]) != "Admin")
              {
                  HyperLink Hlnk = e.Row.FindControl("HyperLink2") as HyperLink;
                  Hlnk.Visible = false;
              }
          }
      }
  </code></pre>
  
  <p>How can I do this within page load? Please guide.</p>