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)文章
JS中批量給元素綁定事件過(guò)程中的相關(guān)問(wèn)題使用閉包解決
解決元素批量綁定事件的時(shí)候,出現(xiàn)i=最后一個(gè)循環(huán)變量的值的方法有兩種:把這個(gè)循環(huán)變量保存起來(lái),不要讓它的作用域在整個(gè)函數(shù),而是在循環(huán)體內(nèi)2013-04-04基于jQuery實(shí)現(xiàn)仿百度首頁(yè)換膚背景圖片切換代碼
現(xiàn)在介紹網(wǎng)頁(yè)換膚的例子已經(jīng)數(shù)不勝數(shù),自己也沒(méi)有仔細(xì)研究過(guò),剛搞遇到類似這個(gè)問(wèn)題,網(wǎng)上查了資料解決了問(wèn)題,感覺(jué)很有用,就記錄了下來(lái),本文給大家分享基于jQuery實(shí)現(xiàn)仿百度首頁(yè)換膚背景圖片切換代碼,需要的朋友可以參考下2015-08-08在jQuery中 關(guān)于json空對(duì)象篩選替換
本篇文章,小編將為大家介紹,在jQuery中 關(guān)于json空對(duì)象篩選替換,有需要的朋友可以參考一下2013-04-04使用簡(jiǎn)潔的jQuery方法實(shí)現(xiàn)隔行換色功能
本篇文章主要介紹了使用簡(jiǎn)潔的jQuery方法實(shí)現(xiàn)隔行換色功能。需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助2014-01-01jQuery實(shí)現(xiàn)帶進(jìn)度條的輪播圖
這篇文章主要為大家詳細(xì)介紹了jQuery實(shí)現(xiàn)帶進(jìn)度條的輪播圖,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-09-09當(dāng)jQuery1.7遇上focus方法的問(wèn)題
如果一定要用最高版本的jQuery,最省事的辦法莫過(guò)于在寫xxx.focus()時(shí),加一個(gè)try/catch,變成try{xxx.focus();}catch(e){}2014-01-01jQuery固定浮動(dòng)側(cè)邊欄實(shí)現(xiàn)思路及代碼
如果頁(yè)面比較高,當(dāng)滾動(dòng)條拖到頁(yè)面的下面的時(shí)候,側(cè)邊欄會(huì)出現(xiàn)一個(gè)固定跟隨瀏覽器的DIV框,下面將思路及具體實(shí)現(xiàn)與大家分享下2014-09-09jQuery中clearQueue()方法用法實(shí)例
這篇文章主要介紹了jQuery中clearQueue()方法用法,實(shí)例分析了clearQueue()方法的功能、定義及進(jìn)行清空隊(duì)列操作的技巧,具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2014-12-12