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

后端 未结 4 896
长发绾君心
长发绾君心 2020-12-06 03:29

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



        
相关标签:
4条回答
  • 2020-12-06 04:02

    You could add a trigger of the gridview

    <Triggers>
          <asp:PostBackTrigger ControlID="gridview1" />
    </Triggers>
    
    0 讨论(0)
  • 2020-12-06 04:17

    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);
       }
    }
    
    0 讨论(0)
  • 2020-12-06 04:21

    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>
    
    0 讨论(0)
  • 2020-12-06 04:23

    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
    
    0 讨论(0)
提交回复
热议问题