Here is my scenario, I have implemented a gridview, when the user press the add button on the page a new row is generated with empty input texts using javascript, after that the user fill the inputs and press the save button, thus all values is sent as an object to a webservice which handles the data insertion. after that i want to refresh the grid, bind (refresh) my gridview and since i am inserting the data from a html button there is no postback. I know that when you access the gridview from javascript it renders as an HTML table is there a way i can bind data to it, Is there any solution ?
1 Answer
this things depends on yous GridView structure, of course you can use HTML DOM model to modify it and insert new row at end of gridview. but there are lot of manual effort required to achieve this and more chances of bugs.
another approach could be use of UpdatePanel.
<ajax:UpdatePanel ID="UpdatePanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView ID="GridView" Visible="false" runat="server" HeaderStyle-Width="200" HeaderStyle-BackColor="#2B6292" HeaderStyle-ForeColor="White"
AllowSorting="true" AllowPaging="true" Width="600" AutoGenerateColumns="False" OnRowCreated="GridView_OnRowCreated"
DataKeyNames="Id" onsorting="GridView_OnSort">
<Columns>
...
</Columns>
</asp:GridView>
</ContentTemplate>
<Triggers>
<ajax:AsyncPostBackTrigger ControlID="CreateButton"/>
</Triggers>
</ajax:UpdatePanel>
please refer to http://blogs.microsoft.co.il/blogs/dorony/archive/2008/05/23/using-updatepanel-to-disable-gridview-view-state.aspx for more information.
3 Comments
yahya kh
I actually would like to use HTMl, but i am at how to retrieve an array of objects to an array object in javascript. whenever i retrieve the data it says object undefined. students = GetAllStudents();
dipak
is it possible to post code, where you making ajax request and webmethod which returns GetAllStudents? basically there is .d or .data property which is array of students.
yahya kh
i made a question regarding it: stackoverflow.com/questions/8429363/…