简体   繁体   中英

Gridview hyperlink click event refresh ajax update panel

How can i do that, when i click on ID in Gridview1 which i make like hyperlink field to refresh only Ajax Update Panel, not all page? What i need in code?

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
    DataKeyNames="id" DataSourceID="SqlDataSource1" CellPadding="4" 
    ForeColor="#333333" GridLines="None" 
    onselectedindexchanged="GridView1_SelectedIndexChanged" Width="232px">
    <AlternatingRowStyle BackColor="White" />
    <Columns>
        <asp:CommandField ShowSelectButton="True" />
        <asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />

        <asp:HyperLinkField 
  DataTextField="id" 
  DataTextFormatString=" {0}" 
  DataNavigateUrlFields="id" HeaderText="id"
  DataNavigateUrlFormatString="WebForm1.aspx?ID={0}"   />
    </Columns>

This is the code for Update Panel, where when i click on ID in GridView1 refresh Update Panel with Gridview2:

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<br />
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">

    <ContentTemplate>
        <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" 
            DataSourceID="SqlDataSource2">
            <Columns>
                <asp:BoundField DataField="id_proba" HeaderText="id_proba" 
                    SortExpression="id_proba" />
                <asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ProbaConnectionString %>" 

        </asp:SqlDataSource>
    </ContentTemplate>
</asp:UpdatePanel>

You need to add the HyperLink as a Postback trigger on Every postback manually in the Page_Load(). Maybe that will solve the problem..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM