回调函数,ICallbackEventHandler。省市县无刷新DropDownList三级联动实现方法讨论!用C#2.0实现。求最新全国省市县Access数据库下载地址。
解决方案 »
- ---刚学asp.net mvc 有个概念性的问题想请教大侠们!
- iframe传值问题?
- 身份验证的问题
- 用javascript修改了服务器控件的值,为什么服务端无法取到
- ASP.NET 2.0中,水晶报表声明的问题
- 100分求一个好用的ComboBox组件(可编辑下拉框)
- ^[^':();\s]*$ 这段正则表达式,是限制字符串中不能有单引号、冒号、括号、分号和空字符,那么我怎么在这个基础上显示用户只能输入6,20个字
- 数据库sql server用window验证方法连接。asp.net连接怎么写啊?
- 水晶报表做出的chart下面怎么有那么多空的<tr>呢?
- ASP.NET备份数据库问题
- [调查+散分] 五一长假大家打算怎么过?
- 求:新闻发布系统生成静态页源码
http://atlas.asp.net/atlastoolkit/CascadingDropDown/CascadingDropDown.aspx
<%@ Page language="c#" Codebehind="Example.aspx.cs" AutoEventWireup="false" Inherits="Webs.other.Example" %>
<HTML>
<HEAD>
<title>Example</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<script>
function load(state){
var drp2 = document.getElementById("DropDownList2");
for (i = drp2.length; i >= 0; i--){
drp2.options.remove(i);
} var oHttpReq = new ActiveXObject("MSXML2.XMLHTTP");
var oDoc = new ActiveXObject("MSXML2.DOMDocument"); oHttpReq.open("POST", "getData.aspx?state="+state, false);
oHttpReq.send("");
result = oHttpReq.responseText;
oDoc.loadXML(result);
items1 = oDoc.selectNodes("//CITY/Table/Id");
items2 = oDoc.selectNodes("//CITY/Table/shiname"); var itemsLength=items1.length;
for(i=0;i<itemsLength;i++) //将小类的类名和编号赋予DropDownList2
{
var newOption = document.createElement("OPTION");
newOption.text=items2[i].text;
newOption.value=items1[i].text;
drp2.options.add(newOption);
}
}
window.onload = function(){load('1');} </script>
</HEAD>
<body MS_POSITIONING="FlowLayout">
<form id="Form1" method="post" runat="server">
<asp:DropDownList id="DropDownList1" runat="server"></asp:DropDownList>
<asp:DropDownList id="DropDownList2" runat="server"></asp:DropDownList>
<asp:TextBox id="TH" runat="server"></asp:TextBox>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
</form>
</body>
</HTML>
cs源文件:using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;namespace Webs.other
{
/// <summary>
/// Example 的摘要说明。
/// </summary>
public class Example : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList DropDownList1;
protected System.Web.UI.WebControls.TextBox TH;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.DropDownList DropDownList2;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!this.IsPostBack)
{
// 建立数据源加载第一个DropDownList,也可以默认加载第二个
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings.Get("connStr1"));
SqlDataAdapter da = new SqlDataAdapter("select Id,shengname from Province",con);
DataSet ds = new DataSet();
da.Fill(ds);
this.DropDownList1.DataSource = ds;
this.DropDownList1.DataTextField = "shengname";
this.DropDownList1.DataValueField = "Id";
this.DropDownList1.DataBind();
// 这里是绑定客户端事件,当第一个DropDownList的选项改变时激发下面的事件onchange,这个事件将调用一个客户端方法load()
this.DropDownList1.Attributes.Add("onchange","load(this.options[this.selectedIndex].value)");
}
} #region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void Button1_Click(object sender, System.EventArgs e)
{
TH.Text=this.Request.Form["DropDownList2"].ToString();
}
}
}getdata源文件
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Xml;
using System.Configuration;
using System.Text;namespace Webs.other
{
/// <summary>
/// GetData 的摘要说明。
/// </summary>
public class GetData : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
//Response.Write(Request["state"]);
int shengNo=int.Parse(Request["state"].ToString());
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings.Get("connStr1"));
SqlDataAdapter da = new SqlDataAdapter("select Id,shiname from City where Shengid='"+shengNo+"'",con);
DataSet ds = new DataSet("CITY");
da.Fill(ds); XmlTextWriter writer = new XmlTextWriter(Response.OutputStream,Encoding.UTF8);
writer.Formatting = Formatting.Indented;
writer.Indentation = 4;
writer.IndentChar = ' ';
writer.WriteStartDocument();
ds.WriteXml(writer);
writer.Flush();
Response.End();
writer.Close();
} #region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
请先安装最新版本的Atlas April CTP:http://www.microsoft.com/downloads/details.aspx?FamilyId=B01DC501-B3C1-4EC0-93F0-7DAC68D2F787&displaylang=en
然后在此下载并安装Atlas Control ToolKit:http://download.microsoft.com/download/B/8/1/B8176A86-5D85-41B8-819B-19A9ACF1CE8C/AtlasControlToolkit.exe 这是该控件包的主页,内有这些控件的演示,安装说明等:http://atlas.asp.net/atlastoolkit/ 该ToolKit包括如下三部分:一个控件包,内含很多Atlas Server Side控件以及相应的源代码,以对现有的ASP.NET控件进行扩展,生成强大的客户端功能。这些控件既是学习开发的好资源,也可以马上用到现有的网站开发中,无须书写任何客户端代码。它包括如下一些控件:
Cascading DropDown:无刷新的级联DropDownList,需要使用UpdatePanel辅助。
Collapsible Panel:客户端可折叠的Panel。
Confirm Button:点击按钮后弹出确认对话框。
Drag Panel:可拖动的Panel。
Hover Menu:提供悬浮菜单的支持。例如鼠标移到GridView的某一行上面,弹出Edit,Delete的悬浮菜单。需要使用UpdatePanel辅助,效率极其低下。
Popup Control:发生某个事件时,在页面上弹出一个控件。可用于例如Date Picker等的开发。同样使用UpdatePanel,效率比较低下。
Reorder List:一个可以在客户端通过拖拽而重新排序的List,需要使用UpdatePanel辅助,效率极其低下。客户端停顿,闪烁较为严重。
Textbox Water:鼠标单击某个Label时,该Label切换到TextBox供用户输入信息,视觉效果很棒。需要使用UpdatePanel辅助。
Toggle Button:将CheckBox用一对图片代替,有丰富的视觉效果,但是因为需要使用UpdatePanel辅助,效率不是很高,有明显的延迟。
一个包含安装说明以及上述控件的演示的Web Site。内容和上面提及的这个ToolKit的主页内容一样。
一个Visual Studio 2005的Project Template,用来开发自定义的Atlas Server Side控件。
注意到上述提供的控件均为服务器端控件,基本上不需要书写客户端JavaScript代码以及Atlas Script。所以使用的难度会减小不少,与传统的ASP.NET服务器端控件一样,只需要拖拽到页面上并设置属性即可。但同时带来的是服务器端性能的开销以及开发难度的加大,同时,上述控件大都需要使用UpdatePanel辅助,产生不必要的服务器通信同时也极大影响了客户端的用户体验。