My solution is not such an elegant way to do this, as Abide Masaraure pointed out. I suggest you follow his answer.
But you can also put each gridview inside another div and set the attribute "runat = server" in these divs .
And for each link, you can use the asp.net linkbutton link (because this element has the appearance of an html link).
Your aspx code will look like this:
<asp:LinkButton runat="server" id="lnkButton_1" text="Link 1" OnClick="lnkButton_1_Click"/> <asp:LinkButton runat="server" id="lnkButton_2" text="Link 2" OnClick="lnkButton_2_Click"/> <asp:LinkButton runat="server" id="lnkButton_3" text="Link 3" OnClick="lnkButton_3_Click"/> <asp:LinkButton runat="server" id="lnkButton_4" text="Link 4" OnClick="lnkButton_4_Click"/> <asp:LinkButton runat="server" id="lnkButton_5" text="Link 5" OnClick="lnkButton_5_Click"/> <div runat="server" id="divGrid_1" Visible="false"> <asp:GridView runat="server" id="grid_1"></asp:GridView> </div> <div runat="server" id="divGrid_2" Visible="false"> <asp:GridView runat="server" id="grid_2"></asp:GridView> </div> <div runat="server" id="divGrid_3" Visible="false"> <asp:GridView runat="server id="grid_3"></asp:GridView> </div> <div runat="server" id="divGrid_4" Visible="false"> <asp:GridView runat="server" id="grid_4"></asp:GridView> </div> <div runat="server" id="divGrid_5" Visible="false"> <asp:GridView runat="server" id="grid_5"></asp:GridView> </div>
Your aspx.cs (codebehind) code will look like this:
protected void lnkButton_1_Click(object sender, EventArgs E) { divGrid_1.Visible = true; divGrid_2.Visible = false; divGrid_3.Visible = false; divGrid_4.Visible = false; divGrid_5.Visible = false; LoadGridView_1(); }
And for each click of the button of the link button, you can set the visibility of the corresponding div to true and the others to false, and then you call the method that loads the corresponding gridview.
I hope I helped you.
Sincerely.
source share