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 ();
}
}
}
}