?
??杩???涓?浜?缃?绔?绋?寮?锛?缁?甯歌??ㄥ?板?涓?涓??????????╋???浜?浠?缁?寮?濮???jaxPro杩?涓??т欢锛???瑙?????涓?????浠ュ??浣跨?ㄨ?MagicAjax锛???甯镐?涓??ㄤ?蹇?璁颁?锛???楹荤????灏辨???ㄨ??????褰????跺??姣?杈?楹荤????靛?碉??ㄧ?涓?涔?????甯稿?锛?涓?杩???瑕????版?圭?甯告病?????版??锛?淇轰?????楦?锛?楂???璇峰拷?ャ?????拌?涓?AjaxPro浣跨?ㄦ??杈?绠???锛?杩?娆′娇?ㄧ????6.x??锛????扮????7.x??锛?瑙?寰?6.0绯诲?????逛究锛?灏遍??浠?浜???
?ㄩ??瑕????版?归?芥????绀轰?锛??镐俊??甯稿?规????????
????? 棣?????eb.config娣诲??杩?涓??ョ????lt;system.web>??</system.web>涔??达?濡?涓?锛?
?? <system.web>
??? <!--for Ajaxnet-->
??? <httpHandlers>
????? <add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro.2"/>
??? </httpHandlers>
???? <!--?朵?璁剧疆-->
?? </system.web>
???? ?跺????AjaxPro.2.dll涓㈠??in??褰?锛??跺??寮??ㄤ?灏辫?戒???
??? 杩?????浠g???э?楹荤???讳?涓???唬???? 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();
??? }
??? /** <summary>
??? /// ?版??搴?杩???http://www.knowsky.com
??? /// </summary>
??? /// <returns></returns>
??? 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;
??????? }
??? }
???
??? /** <summary>
??? /// ?峰??涓?绾у??绫???? /// </summary>
??? [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;
??????? }
??? }
???
??? /** <summary>
??? /// 杩???涓?涓?DataSet
??? /// </summary>
??? /// <param name="SQL"></param>
??? /// <returns></returns>
??? 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;
??????? }
??? }
??? /** <summary>
??? /// //?版??缁?瀹?
??? /// </summary>
??? 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" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
??? <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
??? <title>AjaxPro瀹??版???锋?颁?绾ц????lt;/title>
</head>
<script language="javascript" type="text/javascript">
????? <!--
?????? // ACLOUD 甯哥??S?芥???????? function getBid(s){
????????? return document.getElementById(s);
??????? }
??????? function getBmc(s){
????????? return document.getElementByName(s);
??????? }
???????
?????? //?剧ず??绫诲??琛??????? function showNext(sid,obj)
??????? {
????????? if(sid==null || sid=="" || sid.length<1)return;
????????? var slt =getBid(obj);
????????? var v = _Default.getNextClass(sid).value; // 绫荤????绉?????????? //alert(v);
????????? //return;
????????? if (v != null){?????
????????? if(v != null && typeof(v) == "object" && v.Tables != null)
??????????????????? {???????
??????????????????????? slt.length = 0;
??????????????????????? slt.options.add(new Option("璇烽????,0));
??????????????????????? //??浜?涓???璇烽???┾??涓昏?涓轰?瑙???onchange浜?浠???????????????????????? if(obj=="ddl2"){
??????????????????????? getBid("ddl3").options.length=0;
??????????????????????? getBid("ddl3").options.add(new Option("璇烽????,0));
??????????????????????? }???????????
??????????????????????? for(var i=0; i<v.Tables[0].Rows.length; i++)
??????????????????????? {
??????????????????????????? var txt = v.Tables[0].Rows[i].txt; //杩?涓??版?归??瑕?娉ㄦ???哄??澶у???
??????????????????????????? var vol = v.Tables[0].Rows[i].vol; //璺?dataset琛ㄧ??????绉拌?涓?????????????????????????????? slt.options.add(new Option(txt,vol));
??????????????????????? }
??????????????????? }
?????????? }???
?????????? return;
??????? }
??????? -->
</script>
<body>
??? <form id="form1" runat="server">
??? <div>
????? <table width="500" align="center" cellpadding="0" cellspacing="0">
??????? <tr>
????????? <td width="99"> </td>
????????? <td width="401">
????????????? ??甯?<asp:DropDownList ID="ddl1" runat="server">
????????????? </asp:DropDownList>
????????????? ?哄??<asp:DropDownList ID="ddl2" runat="server">
????????????? </asp:DropDownList>
????????????? ?卞??<asp:DropDownList ID="ddl3" runat="server">
????????????? </asp:DropDownList></td>
??????? </tr>
??????? <tr>
????????? <td> </td>
????????? <td> </td>
??????? </tr>
??????? <tr>
????????? <td> </td>
????????? <td> </td>
??????? </tr>
????? </table>
???
??? </div>
??? </form>
</body>
</html>
?
?
- 浠ヤ???瀹圭????澶???缃? ?????寸??锛?濡?杞?杞借?锋敞???????哄?锛?骞朵???杩?涓??ㄥ????瀹广??