Asp.net Jquery + ajax request data is displayed in the GridView

Source: Internet
Author: User

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>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.