加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

ASP.NET – 将UpdatePanel触发器添加到gridview内的LinkBut??ton

发布时间:2020-12-16 07:31:50 所属栏目:asp.Net 来源:网络整理
导读:我试图更新模态对话框的内容,这段代码适合我: asp:LinkButton ID="updateSomething" runat="server" Text="Update" CausesValidation="false" OnClientClick="openDialog();" onclick="UpdateButton_Click" /asp:UpdatePanel ID="upNewUpdatePanel" runat="
我试图更新模态对话框的内容,这段代码适合我:

<asp:LinkButton ID="updateSomething" runat="server" Text="Update" CausesValidation="false" OnClientClick="openDialog();" onclick="UpdateButton_Click" />

<asp:UpdatePanel ID="upNewUpdatePanel" runat="server">
    <ContentTemplate>
        <asp:Label ID="updateLabel" runat="server"></asp:Label>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="updateSomething" EventName="Click" />
    </Triggers>
</asp:UpdatePanel>

但是,当我尝试将LinkBut??ton放在gridview中时,如下所示:

<asp:GridView ID="grdListUsers" runat="server" AutoGenerateColumns="false" AllowPaging="false" OnRowDataBound="grdRowDefListUsers" CssClass="mGrid" EmptyDataText="No users.">
    <Columns>
        <asp:BoundField DataField="Name" HeaderText="Nome" HeaderStyle-Width="300" />
        <asp:BoundField DataField="Login" HeaderText="Login" HeaderStyle-Width="300" />
        <asp:TemplateField HeaderText="Options" HeaderStyle-Width="75" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle">
            <ItemTemplate>
                <asp:LinkButton ID="updateSomething" runat="server" Text="Update" CausesValidation="false" OnClientClick="openDialog();" onclick="UpdateButton_Click" />
        </asp:TemplateField>
    </Columns>
</asp:GridView>

这不起作用,我得到一个错误说:在UpdatePanel’updNewUpdatePanel’中找不到ID为’updateSomething’的控件.

如何在gridview中使用ImageButton?

解决方法

尝试将asp:AsyncPostBackTrigger添加到asp:GridView的OnRowCommand事件并处理该事件中的链接按钮单击

<asp:GridView ID="grdListUsers" runat="server" onRowCommand="grdListUsers_RowCommand">
     <asp:TemplateField>
           <asp:LinkButton ID="updateSomething" CommandName="update-something" CommandArgument='<%# DataBinder.Eval(Container,"RowIndex") %>'/>
     </asp:TemplateField>
</asp:GridView>

并在cs中创建这样的事件

protected void grdListUsers_RowCommand(object sender,GridViewCommandEventArgs e)
{
   if (e.CommandName == "update-something")
   {
      grdListUsers.SelectedIndex = Convert.ToInt32(e.CommandArgument);
   }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读