ASP.NET - Adding an UpdatePanel trigger to a LinkButton inside a gridview

拜拜、爱过 提交于 2019-11-28 09:30:56
Atzoya

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>

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);
   }
}
Telan Niranga

Add another Update Panel surrounding your link button just like below.

<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:UpdatePanel ID="aa" runat="server">
                    <ContentTemplate>
                        <asp:LinkButton ID="updateSomething" runat="server" Text="Update" CausesValidation="false" OnClientClick="openDialog();" onclick="UpdateButton_Click" />
                    </ContentTemplate>
                    <Triggers>
                        <asp:PostBackTrigger  ControlID="updateSomething"/>
                    </Triggers>
              </asp:UpdatePanel>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

You could set the UpdatePanel's UpdateMode to Conditional and update it manually from the UpdateButton_Click-Handler:

<asp:UpdatePanel ID="UdpFormPanel" runat="server" UpdateMode="conditional" ChildrenAsTriggers="false"  >

LinkButton's Click-Event handler:

Protected Sub UpdateButton_Click(ByVal sender As Object, ByVal e As EventArgs)
    'blah....
    upNewUpdatePanel.Update()
End Sub

You could add a trigger of the gridview

<Triggers>
      <asp:PostBackTrigger ControlID="gridview1" />
</Triggers>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!