asp.net - JavaScript code for fetching list of items into a GridView -


i have asp.net web application. on page_load grid view items created. have <asp:textbox> , search button. using pagemethods rid of postback. idea when button clicked call javascript function , call webmethod. webmethod returns list of items based on searched criteria.

how can fetch these items , populate gridview them?

in other words partial update - on button click supposed update gridview.

here code webmethod:

[webmethod]     public static list<item> searchresults(string text)     {         itemfunctions item_functions = new itemfunctions();         list<item> items = new list<item>();         items = item_functions.searchresults(text);         return items;     } 

and here gridview, button , textbox:

<asp:scriptmanager id="scriptmanager1" runat="server" enablepagemethods="true" /> <asp:textbox id="search_textbox" runat="server" />         <input type="button" id="button1" value="search" onclick="searchresults();" />         <div id="searchresults_gridview" >             <asp:gridview id="gridview1" allowpaging="true" gridlines="both" runat="server" allowsorting="true"             autogeneratecolumns="false"             width="740px"             causesvalidation="false">             <columns>                 <asp:boundfield datafield="item_name" headertext="item_name" />                 <asp:boundfield datafield="item_description" headertext="item_description" />                 <asp:boundfield datafield="item_quantity" headertext="item_quantity" />                 <asp:boundfield datafield="category_name" headertext="category_name" />                 <asp:boundfield datafield="type_name" headertext="type_name" />                 <asp:boundfield datafield="item_available" headertext="item_available" />                 <asp:boundfield datafield="item_serial_number" headertext="item_serial_number" />                 <asp:boundfield datafield="item_permission_status" headertext="item_permission_status" />                 <asp:boundfield datafield="item_location" headertext="item_location" />                 <asp:commandfield showselectbutton="true" selecttext="view" />             </columns>         </asp:gridview>         </div> 

this searchresults functions called on button click:

<script>     function searchresults() {         pagemethods.searchresults(onsucceeded, onfailed);     }      function onsucceeded(result, usercontext, methodname) {     }      function onfailed(error, usercontext, methodname) {         alert("an error occured :(");     } </script> 

my javascript skills bad , still learning, otherwise in theory think rest of code should work.

you can in javascript, @ point require dump gridview's html (because after gridview has rendered html) , re-create html table. while may preferred solution lose data on full postback , required re-run javascript.

you using updatepanel functionality. see following links on using updatepanels :

http://msdn.microsoft.com/en-us/library/bb386454(v=vs.100).aspx

how use updatepanel in asp.net without refreshing page?


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -