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 ?
Asked
Active
Viewed 5,520 times
1
-
There is a solution that i think maybe will work but i will have to try it, which is empty the gridview table and construct again by adding each cell it. – yahya kh Dec 07 '11 at 14:12
1 Answers
2
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.

dipak
- 2,011
- 2
- 17
- 24
-
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(); – yahya kh Dec 07 '11 at 14:34
-
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. – dipak Dec 08 '11 at 00:03
-
i made a question regarding it: http://stackoverflow.com/questions/8429363/retrive-value-from-webservice-called-from-javascipt – yahya kh Dec 08 '11 at 10:23