All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
在C#中应用哈希表
MDF文件在SQL Server中的恢复技术_[SQL Server教程]
新手通过实例学习动态网页PHP的语法_php资料_编程技术
整站如何防止SQL注入攻击_[Asp.Net教程]
初学PHP的朋友来看:PHP语法学习笔记_php资料_编程技术
网页中添加新浪天气预报的几种方法_[Asp.Net教程]
随机验证图片的产生,asp.net,2.0,c#,---在网页的特定或莫个位置显示图片_[Asp.Net教程]
PHP程序加速探索之代码优化_[PHP教程]
用一句SQL取出第m条到第n条记录的方法_[SQL Server教程]
PHP读取汉字点阵数据_php资料_编程技术
Reading number is top 10 pictures
Fury xp desktop theme
Wear bikinis cock
More attractive than sora aoi4
Fan bingbing black wings for platform and DanLuoWang believes beauty2
Japan sexy beauty passion photo
Sora aoi on twitter4
The little girl with long hair1
Players in the eyes of a perfect love1
Summer is most suitable for young people to travel in China7
Chinese paper-cut grilles art appreciation4
Download software ranking
Tram sex maniac 2 (H) rar bag17
Sora aoi‘s film--Lust fan wall
Prostitutes diary
网络管理员第三版
C#编程思想
Boxer's Top ten classic battle7
XML+Web+Service开发教程
Tram sex maniac 2 (H) rar bag9
WebService在.NET中的实战应用教学视频 → 第1集
Unix video tutorial6
归海一刀 published in(发表于) 2014/1/30 0:51:11 Edit(编辑)
asp.net,2.0,客户端回调实现全国省市县3级联动下拉列表_[Asp.Net教程]

asp.net,2.0,客户端回调实现全国省市县3级联动下拉列表_[Asp.Net教程]

asp.net 2.0 客户端回调实现全国省市县3级联动下拉列表_[Asp.Net教程]























asp.net 2.0 客户端回调实现全国省市县3级联动下拉列表
从网上看到一些相关的例子,发现代码较繁。最近自己修改了一下,贴出与君共勉。




客户端:




<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default4.aspx.cs" Inherits="Default4" %>









无标题页







onclick='select("ddl1");'>

onclick='select("ddl2");'>











服务器端:




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;




public partial class Default4 : System.Web.UI.Page,System.Web.UI.ICallbackEventHandler
{
private System.Data.SqlClient.SqlCommand sqlSelectCommand1;
private System.Data.SqlClient.SqlConnection sqlConnection1;
private System.Data.SqlClient.SqlDataAdapter da_pro;
private System.Data.SqlClient.SqlCommand sqlSelectCommand2;
private System.Data.SqlClient.SqlCommand sqlSelectCommand3;
private System.Data.SqlClient.SqlDataAdapter da_dis;
private System.Data.SqlClient.SqlDataAdapter da_city;
private ds ds1;
private string ret;




protected void Page_Load(object sender, EventArgs e)
{
InitializeComponent();
da_pro.Fill(ds1);
itemadd(ds1.province.DefaultView, ddl1);
String cbReference = Page.ClientScript.GetCallbackEventReference(this, "arg", "ReceiveServerData", "context");
String callbackScript;
callbackScript = "function CallTheServer(arg,context)" +
"{ " + cbReference + "} ;";
Page.ClientScript.RegisterStartupScript(this.GetType(), "abcdefg", callbackScript, true);
}




private void InitializeComponent()
{
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.da_pro = new System.Data.SqlClient.SqlDataAdapter();
this.sqlSelectCommand2 = new System.Data.SqlClient.SqlCommand();
this.da_city = new System.Data.SqlClient.SqlDataAdapter();
this.sqlSelectCommand3 = new System.Data.SqlClient.SqlCommand();
this.da_dis = new System.Data.SqlClient.SqlDataAdapter();
this.ds1 = new ds();
((System.ComponentModel.ISupportInitialize)(this.ds1)).BeginInit();
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT provinceID, province FROM province";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "Data Source=localhost,2433;Initial Catalog=cargo;Persist Security Info=True;User " +
"ID=sa;Password=alan";
this.sqlConnection1.FireInfoMessageEventOnUserErrors = false;
//
// da_pro
//
this.da_pro.SelectCommand = this.sqlSelectCommand1;
this.da_pro.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "province", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("provinceID", "provinceID"),
new System.Data.Common.DataColumnMapping("province", "province")})});
//
// sqlSelectCommand2
//
this.sqlSelectCommand2.CommandText = "SELECT cityID, city FROM city WHERE (father = @pro)";
this.sqlSelectCommand2.Connection = this.sqlConnection1;
this.sqlSelectCommand2.Parameters.AddRange(new System.Data.SqlClient.SqlParameter[] {
new System.Data.SqlClient.SqlParameter("@pro", System.Data.SqlDbType.NVarChar, 6, "father")});
//
// da_city
//
this.da_city.SelectCommand = this.sqlSelectCommand2;
this.da_city.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "city", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("cityID", "cityID"),
new System.Data.Common.DataColumnMapping("city", "city")})});
//
// sqlSelectCommand3
//
this.sqlSelectCommand3.CommandText = "SELECT areaID, area FROM area WHERE (father = @city)";
this.sqlSelectCommand3.Connection = this.sqlConnection1;
this.sqlSelectCommand3.Parameters.AddRange(new System.Data.SqlClient.SqlParameter[] {
new System.Data.SqlClient.SqlParameter("@city", System.Data.SqlDbType.NVarChar, 6, "father")});
//
// da_dis
//
this.da_dis.SelectCommand = this.sqlSelectCommand3;
this.da_dis.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "area", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("areaID", "areaID"),
new System.Data.Common.DataColumnMapping("area", "area")})});
//
// ds1
//
this.ds1.DataSetName = "ds";
this.ds1.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema;
((System.ComponentModel.ISupportInitialize)(this.ds1)).EndInit();




}




private void itemadd(DataView dv, DropDownList ddl)
{
while (ddl.Items.Count > 1)
ddl.Items.RemoveAt(ddl.Items.Count - 1);
foreach (DataRowView drv in dv)
{
ListItem li = new ListItem();
li.Text = drv[1].ToString();
li.Value = drv[0].ToString();
ddl.Items.Add(li);
}
}
public void RaiseCallbackEvent(string eventarg)
{
string getparm = eventarg;
string[] sinfo = getparm.Split(',');
switch (sinfo[0])
{
case "ddl1":
{
da_city.SelectCommand.Parameters[0].Value = sinfo[1];
da_city.Fill(ds1);
ret="ddl2,";
foreach (DataRow row in ds1.city)
{
ret += row["cityID"] + "@" + row["city"] + ",";
}
break;
}
case "ddl2":
{
da_dis.SelectCommand.Parameters[0].Value = sinfo[1];
da_dis.Fill(ds1);
ret = "ddl3,";
foreach (DataRow row in ds1.area)
{
ret += row["areaID"] + "@" + row["area"] + ",";
}
break;
}
case "ddl3":
{
break;
}

}
ret.Remove(ret.Length - 1);
}




public string GetCallbackResult()
{
return ret;
}




}




实现效果:










数据库采用 csdn里可以得到的 area.mdb 转入sqlsrv




来源:csdn














































添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.