1

我希望有人能帮助我。我在网上搜索了一个合适的答案,但没有找到。

LinkButtonGridView( GridView2) 中有以下内容,它在一UpdatePanel组 to 中UpdateMode='Conditional'

<ItemTemplate>
    <asp:LinkButton ID="lblSCcomments" runat="server" Width="80" 
        Text='<%#Eval("ShortCode")%>' CommandName="hyperSC" 
        OnCommand="GridView2_Command" 
        CommandArgument='<%#Eval("ShortCode")%>'/>
</ItemTemplate>

后面有这段代码:

protected void GridView2_Command(object sender, CommandEventArgs e)
{
    if (e.CommandName == "hyperSC")
    {
        string sc = e.CommandArgument.ToString();            
        lblShortCode.Text = sc;
        Session["scode"] = sc;
        Server.Transfer("~/MemberPages/reviews.aspx");
    }
 }

不幸的是,当我单击链接时,该命令没有触发。但这在UpdatePanel. 我不需要Gridview刷新,只需要用所选行填充Session变量和lblShortCode标签Shortcode并重定向到另一个页面。

4

1 回答 1

0

您必须OnRowCommand在您的 GridView 中添加事件,<asp:GridView ID="GridView2" runat="server" OnRowCommand="GridView2_RowCommand">并在此事件中添加.CS代码:

protected void GridView2_RowCommand(object sender, CommandEventArgs e)
{
    if (e.CommandName == "hyperSC")
    {
        string sc = e.CommandArgument.ToString();            
        lblShortCode.Text = sc;
        Session["scode"] = sc;
        Server.Transfer("~/MemberPages/reviews.aspx");
    }
}

OnCommand并从 LinkBut​​ton中删除事件。

于 2017-07-15T11:08:49.780 回答