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

Reading number is top 10 articles
SQL Server 2005 存储过程写报表举例_[SQL Server教程]
利用PHP和AJAX创建RSS聚合器_[PHP教程]
教你用PHP写MySQL数据库用户认证系统_php资料_编程技术
XSL教程:匹配模式的学习_[XML教程]
用javascript实现页面无刷新更新数据_JavaScript技术_编程技术
教你安装SQL Server 2005示例数据库_[SQL Server教程]
LINQ体验(9)——LINQ,to,SQL语句之Insert、Update、Delete操作
ASP.NET技巧:请求网址并解析返回的html_[Asp.Net教程]
从VS2003(.net1.1)升级到vs2005(.net2.0)全程跟踪记录_[Asp.Net教程]
ASP.NET重定向方法大总结_.net资料_编程技术
Reading number is top 10 pictures
看看什么叫美景
NeedWallpaper14
The real super beauty3
初五接财神啦!五路财神齐来到
[猫扑大杂烩]华东师范墙上看到的捐精告示 15毫升3600元
Angie Chiu vijara myth1
Plump breasts1
胸部遭到偷窥的女人们
Beauty ZhiHuiLin1
心有鱼而力不足
Download software ranking
apache-tomcat-6.0.33
美女写真1
Tram sex maniac 2 (H) rar bag12
Boxer Classic video3
The Bermuda triangle2
Boxer vs Yellow4
Tram sex maniac 2 (H) rar bag10
Tram sex maniac 2 (H) rar bag7
Visual C++界面编程技术
Professional killers2 data package
delv published in(发表于) 2014/1/23 3:15:27 Edit(编辑)
轻松实现无刷新三级联动菜单[VS2005与AjaxPro]_[Asp.Net教程]

轻松实现无刷新三级联动菜单[VS2005与AjaxPro]_[Asp.Net教程]

轻松实现无刷新三级联动菜单[VS2005与AjaxPro]_[Asp.Net教程]























最近做一些网站程序,经常要用到多个下拉菜单选择,看了介绍开始用AjaxPro这个控件,感觉效果不错。以前使用过MagicAjax,很久不用了忘记了,最麻烦的就是在虚拟目录的时候比较麻烦,呵呵,在网上也有很多,不过重要的地方经常没提醒新手,俺也是菜鸟,高手请忽略。看到这个AjaxPro使用比较简单,这次使用的是6.x的,最新的是7.x的,觉得6.0系列的方便,就选它了。
在重要的地方都有提示了,相信很容易看懂。
首先在web.config添加这个接点 在之间,如下:











然后把AjaxPro.2.dll丢到bin文件夹,然后引用它就可以了。
还是发代码吧,麻烦死了下面代码是 Default.aspx.cs的
using System;
using System.Data;
using System.Configuration;
using System.Data.OleDb;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;




public partial class _Default : System.Web.UI.Page
{

protected void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(_Default)); //必要的
if(!IsPostBack)BindDc();
}




/**////


/// 数据库连接
///

///
public OleDbConnection myConn()
{
string ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + System.Web.HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["dbpath"]);
OleDbConnection conn = new OleDbConnection(ConnStr);
try
{
conn.Open();
return conn;
}
catch
{
throw;
}
}

/**////
/// 获取下级分类
///

[AjaxPro.AjaxMethod]
public DataSet getNextClass(string cid)
{
//因为不希望页面可以知道字段名称 所以 as txt,id as vol 如果是sql ser 可以用 =
//页面获取的 列名称 必须跟这个一同样 而且区分大小写 一般都是这个地方容易疏忽了
//所以二级分类没变化
string sql = @"select cname as txt,id as vol from webclass where parentid=" + cid;
try
{
return getDs(sql);
}
catch
{
//throw;
return null;
}
}




/**////


/// 返回一个DataSet
///

///
///
public DataSet getDs(string SQL)
{
OleDbConnection conn = myConn();
DataSet Ds = new DataSet();
OleDbDataAdapter Da = new OleDbDataAdapter(SQL, conn);
try
{
Da.Fill(Ds);
return Ds;
}
catch
{
return null;
//throw;
}




}
/**////


/// //数据绑定
///

private void BindDc()
{
//第一个
string sql = @"select * from webclass where Parentid=0";
ddl1.DataSource = getDs(sql);
ddl1.DataTextField = "cname";
ddl1.DataValueField = "id";
ddl1.DataBind();
if (ddl1.DataSource != null) ddl1.Attributes.Add("onchange", "showNext(this.options[selectedIndex].value,'ddl2');");





//可以先判断 DropDownList.SelectedItem.Value
//第二个
sql = @"select * from webclass where parentid=" + ddl1.SelectedItem.Value;
ddl2.DataSource = getDs(sql);
ddl2.DataTextField = "cname";
ddl2.DataValueField = "id";
ddl2.DataBind();

//第三个
if (ddl2.DataSource != null) ddl2.Attributes.Add("onchange", "showNext(this.options[selectedIndex].value,'ddl3');");
sql = @"select * from webclass where parentid=" + ddl2.SelectedItem.Value;
ddl3.DataSource = getDs(sql);
ddl3.DataTextField = "cname";
ddl3.DataValueField = "id";
ddl3.DataBind();

}
}
default.aspx内容:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>










AjaxPro实现无刷新三级联动















&nbsp;





城市

区域

花园











&nbsp;




&nbsp;










&nbsp;




&nbsp;

















相关文件:http://www.cnblogs.com/Files/asboy/AjaxDropDownlist.rar

代码文件于2005-5-13更新过 列出了取值的方法




来源:asboy的cnblogs













































添加到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.