1

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
  • 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. Commented Dec 7, 2011 at 14:12

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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();
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.
i made a question regarding it: stackoverflow.com/questions/8429363/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.