0

I have a series of Hide/Show LinkButtons dynamically created. Each button corresponds with a GridView. I want to have the OnClick event of the button Hide or Show the GridView. How do I reference the specific corresponding GridView in the HideButtonClick method. I used a counter num to make each LinkButton.ID unique ID="hidebutton" + num.

            LinkButton lbShow = new LinkButton();
            lbShow.ID = "lbShow" + num;
            lbShow.OnClientClick = "HideCourse_btnClick";
            lbShow.CommandArgument = "" + num;

And in the event method I want something to the effect of

protected void HideCourse_btnClick(object sender, EventArgs e)
{
    grdvw1.Visible = false
}

where the ID grdwv1 is generated by adding the CommandArgument num to the GridView grdvw

Jenny54321
  • 47
  • 1
  • 2
  • 7
  • Do you want to achieve this with asp.net (server side)? or client side with javascript or jQuery? Can you also post your HTML produced with your code? – Subliminal Hash Mar 17 '13 at 22:28
  • 1
    i'm not very familiar with ASP.NET but should event referencing be written as lbShow.OnClientClick += HideCourse_btnClick;? – Mo Patel Mar 18 '13 at 00:16

2 Answers2

0

Consider to use a Repeater with a LinkButton inside the ItemTemplate. Then use Repeater ItemCommand event to handle LinkButtons click events.

0

add this line

LinkButton1.CommandName = "cmdnum";

add RowCommand event to your gridview

protected void yourgridview_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "cmdnum")
        {
            this.FindControl("grdwv" + e.CommandArgument).Visible = false;
//i am assuming other gridview is on your .aspx page
        }
    }
Sharique Ansari
  • 1,458
  • 1
  • 12
  • 22