欢迎来到代码驿站!

jquery

当前位置:首页 > 网页前端 > jquery

Jquery+ajax请求data显示在GridView上(asp.net)

时间:2022-03-21 09:28:18|栏目:jquery|点击:
AJAXLoadProgressForm.aspx:
复制代码 代码如下:

<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">
<img alt="Loading" src="Images/ajax-loader.gif" />Loading......
</div>
<div id="ShowSearchResult">
</div>
</form>

GetGridViewByConditionForm.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插件EasyUI EasyUI创建树形网络(1)

栏    目:jquery

下一篇:jquery 获取标签名(tagName)示例代码

本文标题:Jquery+ajax请求data显示在GridView上(asp.net)

本文地址:http://www.codeinn.net/misctech/196775.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有