Jquery+ajax請(qǐng)求data顯示在GridView上(asp.net)
更新時(shí)間:2010年08月27日 21:51:46 作者:
Jquery ajax請(qǐng)求data顯示在asp.net中GridView控件上,需要的朋友可以參考下。
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();
}
}
}
}
復(fù)制代碼 代碼如下:
<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:
復(fù)制代碼 代碼如下:
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();
}
}
}
}
相關(guān)文章
基于jQuery實(shí)現(xiàn)動(dòng)態(tài)搜索顯示功能
這篇文章主要介紹了基于jQuery實(shí)現(xiàn)動(dòng)態(tài)搜索顯示功能的相關(guān)資料,輸入數(shù)值自動(dòng)匹配相關(guān)信息,感興趣的小伙伴們可以參考一下2016-05-05
Jquery圖片延遲加載插件jquery.lazyload.js的使用方法
這篇文章主要介紹了Jquery圖片延遲加載插件jquery.lazyload.js的使用方法,需要的朋友可以參考下2014-05-05
jQuery+CSS實(shí)現(xiàn)菜單滑動(dòng)伸展收縮(仿淘寶)
淘寶網(wǎng)上的菜單滑動(dòng)伸展收縮想必大家不會(huì)很陌生吧,接下來本文也使用jquery+css實(shí)現(xiàn)一個(gè),代碼很簡(jiǎn)潔功能很使用,感興趣的各位可以不要錯(cuò)過了哈2013-03-03
MultiSelect左右選擇控件的設(shè)計(jì)與實(shí)現(xiàn)介紹
由于項(xiàng)目中用到左右選擇的控件,網(wǎng)上找了一些相關(guān)的實(shí)現(xiàn),基本上有兩個(gè):1、基于JQuery UI的控件2、某個(gè)兄弟手寫的一個(gè)控件,具體實(shí)現(xiàn)如下,感興趣的朋友可以參考下哈2013-06-06
Jquery實(shí)現(xiàn)的簡(jiǎn)單輪播效果【附實(shí)例】
下面小編就為大家?guī)硪黄狫query實(shí)現(xiàn)的簡(jiǎn)單輪播效果【附實(shí)例】。小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考2016-04-04

