asp.net Jquery+ajax请求data显示在GridView
这是一款简单的实用的jquery+ajax请求data显示在gridview的asp教程.net程序哦,下面我们来看看关于如何让ajax返回的值显示在asp.net教程 data显示在gridview上吧。
aspx文件
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代码
<script src="js/jquery-1.4.2.js" type="text/网页特效"></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">
<img alt="loading" src="images/ajax-loader.gif" />loading......
</div>
<div id="showsearchresult">
</div>
</form>
补充:asp.net教程,.Net开发