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里的代码
查看全文
相关阅读:
Mysql 第一天
Jquery day02
Jquery day01
Spring day04笔记(SVN讲解和回顾昨天知识)
Spring day03笔记
Spring day02笔记
Spring day01笔记
python3--命名空间字典
python3--__call__拦截调用
python3--__radd__处理右侧加法
原文地址:https://www.cnblogs.com/xiaotuni/p/2365813.html
最新文章
向2016年说拜拜,继续我的安全开发
iOS微信第三方登录实现
class-dump 反编译私有的库和应用
利用私有的库MobileCoreServices检测正在安装的应用
应用内添加指纹识别
企业级应用发布流程
通过安装一个描述文件在控制台获得设备的udid
获得设备的唯一标识符UDID
Memcache 分布式存储 【一致性Hash】crc32
常用的四种设计模式 PHP代码
热门文章
Linux Awk使用案例总结(nginx日志统计,文件对比合并等)
雅虎34条军规
Mysql Group by 分组取最小的实现方法
Centos下Yum安装PHP5.5,5.6,7.0及扩展
gitlab root 账号 忘记密码如何重置
linux centos6.5支持ipv6
linux 删除进程的多种方法
MySQL 第九天(核心优化三)
MySQL 第八天(核心优化二)
MySQL 第七天(核心优化一)
Copyright © 2011-2022 走看看