Monday, March 26, 2012

Updating DataGrid control with ajax

Hi,

First post here (hope it's in the right forum)-go easy on me-I'm new to ajax!

Okay, so I have a control, which populates a datagrid, given two values (from seperate controls). Basically I want to make it so that pressing the update button will reload just the function that fills the datagrid and not the whole page, if you see what I mean.

I think I need to be using an update panel but the server side end is confusing me.

Thanks

The easiest way is going to be, put your Datagrid (I think you mean gridview) and your button inside an update panel.

Wire the buttons onclick event up to to just redatabind the grid. Here's an example: This example uses an unbound gridview, because I dont have any data currently to bind one too, but you'rs would be bound and work the same.

 <asp:UpdatePanel ID="update1" runat="server" UpdateMode="conditional" ChildrenAsTriggers="true"> <ContentTemplate> <asp:GridView ID="gv1" runat="server"> </asp:GridView> <asp:Button ID="button1" runat="server" Text="Update Grid" OnClick="button1_Click" /> </ContentTemplate> </asp:UpdatePanel>

Protected Sub button1_Click(ByVal senderAs Object,ByVal eAs System.EventArgs) gv1.DataBind()End Sub
Give it a shot, if you run into problems, post back and let us know, we can help you further.


Sorry I havent replied sooner, I've been having problems populating my gridview. I'll come back and look at it once I have the function that takes the two values and returns the dataset :)

No comments:

Post a Comment