This is a simple and practical Jquery + ajax request data is displayed in the asp.net program of the GridView. Let's take a look at how to display the ajax return value in asp.net data on the GridView.
This is a simple and practical asp tutorial for displaying jquery + ajax request data in the gridview. net program. Let's take a look at how to display the value returned by ajax in the asp.net tutorial data on the gridview.
Aspx File
Protected void page_load (object sender, eventargs e)
{
If (request ["id"]! = Null)
{
Sqlconnection conn = null;
Sqlcommand cmd = null;
Sqldataadapter adapter = null;
Try
{
Conn = new sqlconnection ();
Conn. connectionstring = configurationmanager. connectionstrings ["northwindconnectionstring"]. connectionstring;
Conn. open ();
Cmd = new sqlcommand ();
Cmd. connection = conn;
Cmd. commandtype = commandtype. text;
String comment STR = "select * from dbo. MERs ";
If (request ["id"]. tostring ()! = String. empty)
{
Repeated STR + = "where customerid = '" + request ["id"]. tostring () + "'";
}
Cmd. commandtext = comment STR;
Adapter = new sqldataadapter (cmd );
Dataset ds = new dataset ();
Adapter. fill (ds );
This. gvdata. datasource = ds;
This. gvdata. databind ();
}
Catch
{
Response. write ("error happend! ");
Response. flush ();
Response. end ();
}
Finally
{
If (adapter! = Null)
{
Adapter. dispose ();
}
If (cmd! = Null)
{
Cmd. dispose ();
}
If (conn! = Null) & (conn. state = connectionstate. open ))
{
Conn. close ();
}
}
}
}
Jquery code
<Script src = "js/jquery-1.4.2.js" type = "text/Webpage effects"> </script>
<Script type = "text/javascript">
Function showprogressdiv (){
Var id = $ ("input # idtxt"). val ();
$. Ajax ({
Type: "get ",
Url: "getgridviewbyconditionform. aspx ",
Data: "id =" + id,
Beforesend: function (){
$ ("Div # progressdiv" ).css tutorial ("display", "block ");
},
Success: function (msg ){
$ ("Div # showsearchresult" cmd.html (msg );
},
Complete: function (){
$ ("Div # progressdiv" ).css ("display", "none ");;
}
});
}
</Script>
<Form id = "form1" runat = "server">
<Div>
<Input type = "text" id = "idtxt" name = "idtxt"/>
<Input type = "button" id = "loadbtn" value = "loaddatagridview" onclick = "showprogressdiv ()"/>
</Div>
<Div id = "progressdiv" style = "display: none">
loading ......
</Div>
<Div id = "showsearchresult">
</Div>
</Form>