dynamically hiding linkbuttons in a gridview
<p>Here is my template field with 2linkbuttons in a gridview. 
How do I hide one of the lnkbuttons depending on the user selection</p>

<pre><code>       &lt;asp:TemplateField HeaderText="Action"&gt;
       &lt;ItemTemplate&gt;
       &lt;table&gt;
       &lt;tr&gt;

       &lt;td align="center"&gt;
       &lt;asp:LinkButton ID="LinkButton1" runat="server" CommandName= "Publish" CommandArgument="&lt;%# Container.DataItemIndex %&gt;"&gt;&lt;/asp:LinkButton&gt;
       &lt;/td&gt;

       &lt;&lt;td align="center"&gt;
        &lt;asp:LinkButton ID="LinkButton2" runat="server"   CommandName= "Block" HeaderText="Block" CommandArgument="&lt;%# Container.DataItemIndex %&gt;"&gt;Block&lt;/asp:LinkButton&gt;
       &lt;/td&gt;

       &lt;/tr&gt;
       &lt;/table&gt;
       &lt;/ItemTemplate&gt;

       &lt;/asp:TemplateField&gt;       


protected void GridView1_OnRowDataBound(object sender, GridViewRowEventArgs e)
    {


   if(Status=="Posted")
   {
            LinkButton lbtn2 = (LinkButton)e.Row.FindControl("LinkButton2");
            lbtn2.Visible = false;
    }
   if(Status=="Publish")
       {
                LinkButton lbtn1 = (LinkButton)e.Row.FindControl("LinkButton1");
                lbtn1.Visible = false;
        }
    }
</code></pre>

<p>I am doing this using 2 linkbuttons in the template field.
Here if the Status == Posted, then hide LinkButton2. 
If ItemType == Published, then hide LinkButton1.</p>

<p>I don't mind using only Linkbutton and set the commandName and commandArgument in aspx.cs`</p>

<p>I am getting an error at...</p>

<pre><code>LinkButton lbtn2 = (LinkButton)e.Row.FindControl("LinkButton2");
lbtn2.Visible = false;
</code></pre>

<p>Error: Object reference not set to an instance pointing to lnbt2.Visible = false;</p>

<p>Any clues, 
Thanks
Sun</p>
