Open new gridview through Hyperlink

拥有回忆 提交于 2019-12-06 06:34:40

Use a LinkButton instead:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" DataKeyNames="UN_AT_Group" OnRowCommand="GridView1_RowCommand" Visible="True">
    <Columns>    
        <asp:TemplateField>
            <ItemTemplate>
                 <asp:LinkButton ID="GotoNextGrid" runat="server" CommandArgument="NextGrid" CommandName="NextGrid" Text="Show Rights">
                 </asp:LinkButton>  
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>  
</asp:GridView>

Do the same for you second GridView but set Visibile="false".

and then catch it in CodeBehind: (Take care, make sure that what I have as Label here can also be something else... Whatever your DataTextField is.

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "NextGrid")
    {
        LinkButton lb = (LinkButton)e.CommandSource;
        GridViewRow gvr = (GridViewRow)lb.NamingContainer;
        Label lbl = gvr.FindControl("GroupDescription") as Label;
        string description = lbl.Text;
        GridView1.Visible = false;
        GridView2.Visible = true;
        FillDataForGridView2(description) //Fill the Data for GridView2 here and pass description as parameter
    }
}

Take care if you use UpdatePanel, then you need to add an Trigger:

<Triggers>
    <asp:AsyncPostBackTrigger ControlID="GridView1" EventName="RowCommand" />
</Triggers>

I hope this helps.

If you have any questions just ask.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!