Jquery + ajax request data is displayed on the GridView (asp.net)

Source: Internet
Author: User

AJAXLoadProgressForm. aspx:
Copy codeThe Code is as follows:
<Script src = "JS/jquery-1.4.2.js" type = "text/javascript"> </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 ("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>

GetGridViewByConditionForm. aspx:
Copy codeThe Code is as follows:
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 ();
}
}
}
}

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.