通过超链接打开新的gridview [英] Open new gridview through Hyperlink

查看:95
本文介绍了通过超链接打开新的gridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在同一页面上通过超链接打开一个新的gridview,我不想关闭现有的gridview,但想要显示另一个gridview,当用户单击此表上的任何超链接时,就会显示另一个gridview。我有一些像下面这样的数据,当我点击任何这些超链接时,我想在同一页面上打开一个新的gridview。新的gridview将有来自不同表格的数据。



我无法插入图片,因为我没有足够的声望,但可以共享我的HTML代码:

 < asp:GridView ID =GridView1runat =serverAutoGenerateColumns =FalseDataSourceID =SqlDataSource1DataKeyNames =UN_AT_Group> 
<列>
< asp:HyperLinkField DataTextField =Group_DescriptionDataNavigateUrlFields =UN_AT_GroupDataNavigateUrlFormatString =〜/ Details.aspx?Id = {0}
< / Columns>
< / asp:GridView>


解决方案

改用LinkBut​​ton:



$ p $ lt; code>< asp:GridView ID =GridView1runat =serverAutoGenerateColumns =FalseDataSourceID =SqlDataSource1DataKeyNames =UN_AT_GroupOnRowCommand = GridView1_RowCommandVisible =True>
<列>
< asp:TemplateField>
< ItemTemplate>
< asp:LinkBut​​ton ID =GotoNextGridrunat =serverCommandArgument =NextGridCommandName =NextGridText =Show Rights>
< / asp:LinkBut​​ton>
< / ItemTemplate>
< / asp:TemplateField>
< /列>
< / asp:GridView>

为第二个 GridView 做同样的事情,但设置 Visibile =false



然后在CodeBehind中捕捉它:(注意,无论你的 DataTextField 是什么。

  protected void GridView1_RowCommand(object sender,GridViewCommandEventArgs e)
{
if(e.CommandName ==NextGrid)
{
LinkBut​​ton lb =(LinkBut​​ton) e.CommandSource;
GridViewRow gvr =(GridViewRow)lb.NamingContainer;
标签lbl = gvr.FindControl(GroupDescription)作为标签;
字符串描述= lbl.Text;
GridView1.Visible = false;
GridView2.Visible = true;
FillDataForGridView2(描述)//在这里为GridView2填充数据并将描述作为参数传递
}
}

请小心使用 UpdatePanel ,th您需要添加触发器

 <触发器> 
< asp:AsyncPostBackTrigger ControlID =GridView1EventName =RowCommand/>
< /触发器>

我希望这有助于您。



如果你有任何问题只是问。


How can I open a new gridview through hyperlink on same page, I don't want to close existing gridview but want to show another gridview adjacent to this one, when user clicks on any hyperlink on this table. I have some data like below and I want to open a new gridview on same page when I click on any of these hyperlinks. New gridview will be having data from different table.

I cannot insert image as I do not have enough reputation but can share my HTML Code:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" DataKeyNames="UN_AT_Group">
    <Columns>
           <asp:HyperLinkField DataTextField="Group_Description" DataNavigateUrlFields="UN_AT_Group" DataNavigateUrlFormatString="~/Details.aspx?Id={0}"
    </Columns>
</asp:GridView>

解决方案

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.

这篇关于通过超链接打开新的gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆