Ajaxloadprogressform.aspx:
Copy Code code 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"). 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 Code code 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 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 ();
}
}
}
}