asp.net jquery+ajax request data display in GridView

Source: Internet
Author: User

This is a simple and practical jquery+ajax request data display in the GridView ASP tutorial. NET program Oh, let's take a look at how to get Ajax to return the values shown in the ASP.net tutorial data displayed 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 cmdstr = "SELECT * from Dbo.customers";
if (request["id"].tostring ()!=string.empty)
{
Cmdstr + = "where customerid= '" + request["id"].tostring () + "'";
}
Cmd.commandtext = Cmdstr;
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/Web 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"). 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>

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.