ASP.NET - 将 UpdatePanel 触发器添加到 gridview 内的 LinkBut​​ton [英] ASP.NET - Adding an UpdatePanel trigger to a LinkButton inside a gridview

查看:23
本文介绍了ASP.NET - 将 UpdatePanel 触发器添加到 gridview 内的 LinkBut​​ton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图更新模态对话框的内容,这段代码对我有用:

I was trying to update the content of a modal dialog, and this code works for me:

<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 中时,如下所示:

However, when I try to place the LinkButton inside a gridview, like so:

<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 'upNewUpdatePanel' 中为触发器找到 ID 为 'updateSomething' 的控件.

This does not work, I get an error saying: A control with ID 'updateSomething' could not be found for the trigger in UpdatePanel 'upNewUpdatePanel'.

如何在 gridview 中使用 ImageButton?

How can I use the ImageButton inside the gridview?

推荐答案

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

Try and add the asp:AsyncPostBackTrigger to the asp:GridView's OnRowCommand event and handle the link button click in that event

<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 中创建这样的事件

and in the cs create the event like this

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

这篇关于ASP.NET - 将 UpdatePanel 触发器添加到 gridview 内的 LinkBut​​ton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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