【问题标题】:C# linkbutton not firing in Gridview within UpdatepanelC# 链接按钮未在更新面板中的 Gridview 中触发
【发布时间】:2013-05-21 11:35:45
【问题描述】:

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

我在GridView (GridView2) 中有以下LinkButton,该UpdatePanel 设置为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 来刷新,只需要用选定的行Shortcode 填充Session 变量和lblShortCode 标签并重定向到另一个页面。

【问题讨论】:

    标签: redirect gridview updatepanel linkbutton


    【解决方案1】:

    您必须在您的 GridView 中添加 OnRowCommand 事件,如 &lt;asp:GridView ID="GridView2" runat="server" OnRowCommand="GridView2_RowCommand"&gt; 并在此事件中 .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");
        }
    }
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多