Click here to Skip to main content
15,039,149 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have used an update panel to show latest records in gridview on click of button without the need to refresh the page.. the code is:

XML
<asp:Button ID="Button1" runat="server" Text="Show"/>

    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
           <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="ObjectDataSource1">
                <Columns>
                <asp:BoundField DataField="Id" HeaderText="Id" SortExpression="Id" />
                    <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />

                </Columns>
            </asp:GridView>
            <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" OldValuesParameterFormatString="original_{0}"
                SelectMethod="GetAll"
                TypeName="NameSelected"
                onobjectcreating="ObjectDataSource1_ObjectCreating">
            </asp:ObjectDataSource>
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
        </Triggers>
    </asp:UpdatePanel>


the problem is: on click of button, the grid is not updated.. Any help???
Posted
Updated 8-Dec-20 2:40am

on your button you are not running any event_handler so only page_load and page life cycle events will occurs better to update data in page_load
   
Use triggers, When you click on button Gridview will update
C#
<Triggers>
    <asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
 </Triggers>
   
Comments
CHill60 8-Dec-20 8:42am
   
What - like the one defined in the original question that isn't working?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900