zoukankan
html css js c++ java
ajax笔记 显示出所城市名称 ShowCity.aspx.cs代码
下面是cs代码
using
System;
using
System.Data;
using
System.Configuration;
using
System.Collections;
using
System.Web;
using
System.Web.Security;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using
System.Web.UI.HtmlControls;
using
System.Text;
using
GetCommand;
//
这是一个连接数据库的DLL
public
partial
class
Ajax_ShowCity : System.Web.UI.Page, ICallbackEventHandler
...
{
/**/
///
<summary>
///
声明一个数据集对象
///
</summary>
private
DataSet lookupData
=
null
;
protected
void
Page_Load(
object
sender, EventArgs e)
...
{
string
js
=
Page.ClientScript.GetCallbackEventReference(
this
,
"
arg
"
,
"
OnServerCallComplete
"
,
"
ctx
"
,
"
OnServerCallError
"
,
true
);
//
这里false表示异步回调; true表示同步回调);
StringBuilder newFunction
=
new
StringBuilder();
newFunction.Append(
"
function StartAsyncCall(arg,ctx)
"
);
newFunction.Append(
"
{
"
);
newFunction.Append( js );
newFunction.Append(
"
}
"
);
Page.ClientScript.RegisterClientScriptBlock(
this
.GetType(),
"
NewAsyncMethod
"
, newFunction.ToString(),
true
);
/**/
///
///
是首页上显示出所有城市出来
///
this
.ShowCity();
this
.lblMessage.Text
=
SetConnection._errorStatus;
this
.lblMessage.Text
+=
SetConnection.status;
}
/**/
///
<summary>
///
显示城市
///
</summary>
private
void
ShowCity()
...
{
string
executeString
=
"
select CityID,CityName from City
"
;
GridView1.DataSource
=
this
.GetLookupValuesFromDatabase(executeString,
"
City
"
);
this
.GridView1.DataBind();
}
/**/
///
<summary>
///
返回一个数据集
///
</summary>
///
<param name="executeString">
sql语句或存储过程
</param>
///
<param name="TableName">
在内存中名和名称
</param>
///
<returns>
ds
</returns>
private
DataSet GetLookupValuesFromDatabase(
string
executeString,
string
TableName)
...
{
DataSet ds
=
GetCommand.SetConnection.getDataSet(executeString, TableName);
return
ds;
}
/**/
///
<summary>
///
返回回调结果
///
</summary>
///
<returns></returns>
public
string
GetCallbackResult()
...
{
/**/
///
///
存放City表中的城市ID号
///
StringBuilder ids
=
new
StringBuilder();
/**/
///
///
存放City表中的城市名称
///
StringBuilder names
=
new
StringBuilder();
int
rowCount
=
0
;
int
numberRows
=
lookupData.Tables[
"
City
"
].Rows.Count;
foreach
(DataRow row
in
lookupData.Tables[
"
City
"
].Rows)
...
{
rowCount
++
;
if
(rowCount
<=
numberRows)
...
{
ids.Append(row[
"
CityID
"
].ToString());
ids.Append(
"
|
"
);
names.Append(row[
"
CityName
"
].ToString());
names.Append(
"
|
"
);
}
//
if (rowCount < numberRows)
//
{
//
}
}
string
returnData
=
string
.Format(
"
{0}~{1}
"
, ids.ToString(), names.ToString());
return
returnData;
}
public
void
RaiseCallbackEvent(
string
eventArgument)
...
{
System.Threading.Thread.Sleep(
2000
);
string
executeString
=
"
select CityID,CityName from City
"
;
lookupData
=
this
.GetLookupValuesFromDatabase(executeString,
"
City
"
);
}
}
下面是html里的代码
查看全文
相关阅读:
装饰器的初识
闭包
匿名函数lambda
内置函数Ⅱ
Java生鲜电商平台-API接口设计之token、timestamp、sign 具体架构与实现(APP/小程序,传输安全)
Java生鲜电商平台-电商中"再来一单"功能架构与详细设计(APP/小程序)
Java生鲜电商平台-商品中心的架构设计与源码解析(小程序/APP)
Java生鲜电商平台-生鲜电商小程序如何做好代码设计?(微信小程序/APP)
Java生鲜电商平台-生鲜电商订单结算系统的深入解析与反思总结
Java生鲜电商平台-生鲜电商高并发下的接口幂等性实现与代码讲解
原文地址:https://www.cnblogs.com/xiaotuni/p/2365813.html
最新文章
112.路径总和
108将有序数组转化为二查搜索树
107.二叉树的遍历层次II
力扣中国101对称二叉树
力扣中国172阶乘后的零
力扣中国100题相同的树
力扣中国70题爬楼梯
LeetCode 8. 字符串转换整数 (atoi)
LeetCode 面试题66. 构建乘积数组
LeetCode 136. 只出现一次的数字
热门文章
LeetCode 面试题68
LeetCode 235. 二叉搜索树的最近公共祖先
LeetCode 面试题68
LeetCode 面试题 01.02. 判定是否互为字符重排
LeetCode 面试题 01.01. 判定字符是否唯一
LeetCode 236. 二叉树的最近公共祖先
LeetCode 69. x 的平方根
常用模块os和sys
常用模块random time datetime
自定义模块及导入方式
Copyright © 2011-2022 走看看