ICallbackEventHandler接口实现多级联动 (转)

从一位老兄的Blog上看到了这个,可是代码却不太全(至少我这里看不全)。于是想办法补充了一点:
1、客户端脚本:

 1 None.gif   function  CallServer()
 2 ExpandedBlockStart.gifContractedBlock.gif  dot.gif {
 3InBlock.gif  var product = "测试";
 4InBlock.gif  <%= ClientScript.GetCallbackEventReference(this"product""ReceiveServerData",null)%>;
 5ExpandedBlockEnd.gif }

 6 None.gif 
 7 None.gif  function  ReceiveServerData(rValue)
 8 ExpandedBlockStart.gifContractedBlock.gif  dot.gif {
 9InBlock.gif  alert(rValue);
10InBlock.gif  window.location.reload();
11InBlock.gif  var tt=document.getElementById("TextBox1");
12InBlock.gif  alert(tt.DataSource);
13ExpandedBlockEnd.gif }

14 None.gif 
15 None.gif  function  selectChange(e)
16 ExpandedBlockStart.gifContractedBlock.gif  dot.gif {
17InBlock.gif  for(var i=0;i<e.options.length;i++)
18ExpandedSubBlockStart.gifContractedSubBlock.gif  dot.gif{
19InBlock.gif   if(e.options[i].selected==true)
20ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{
21InBlock.gif    selectSon(e.options[i].value); break;
22ExpandedSubBlockEnd.gif   }

23ExpandedSubBlockEnd.gif  }

24ExpandedBlockEnd.gif }

25 None.gif 
26 None.gif  function  selectSon(e) 
27 ExpandedBlockStart.gifContractedBlock.gif  dot.gif {
28InBlock.gif  <%= ClientScript.GetCallbackEventReference(this"e""ReceiveServerData",null)%>;
29ExpandedBlockEnd.gif }

30 None.gif 
31 None.gif  function  ReceiveServerData(rValue)
32 ExpandedBlockStart.gifContractedBlock.gif  dot.gif {
33InBlock.gif  var son=form1.elements["SelSon"];
34InBlock.gif  var s=rValue.split("|");
35InBlock.gif  son.length=s.length;
36InBlock.gif  for(var i=0;i<s.length-1;i++)
37ExpandedSubBlockStart.gifContractedSubBlock.gif  dot.gif{
38InBlock.gif   son.options[i+1]=new Option(s[i],s[i]);
39ExpandedSubBlockEnd.gif  }

40ExpandedBlockEnd.gif }

41 None.gif  // ///
42 None.gif   function  selectChangeSon(e)
43 ExpandedBlockStart.gifContractedBlock.gif  dot.gif {
44InBlock.gif  for(var i=0;i<e.options.length;i++)
45ExpandedSubBlockStart.gifContractedSubBlock.gif  dot.gif{
46InBlock.gif   if(e.options[i].selected==true)
47ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{
48InBlock.gif    select(e.options[i].value); break;
49ExpandedSubBlockEnd.gif   }

50ExpandedSubBlockEnd.gif  }

51ExpandedBlockEnd.gif }

52 None.gif 
53 None.gif  function  select(e)
54 ExpandedBlockStart.gifContractedBlock.gif  dot.gif {
55InBlock.gif  <%= ClientScript.GetCallbackEventReference(this"e""hello",null)%>;
56ExpandedBlockEnd.gif }

57 None.gif 
58 None.gif  function  hello(rValue)
59 ExpandedBlockStart.gifContractedBlock.gif  dot.gif {
60InBlock.gif  var child=form1.elements["Sel"];
61InBlock.gif  var s=rValue.split("|");
62InBlock.gif  child.length=s.length;
63InBlock.gif  for(var i=0;i<s.length-1;i++)
64ExpandedSubBlockStart.gifContractedSubBlock.gif  dot.gif{
65InBlock.gif   child.options[i+1]=new Option(s[i],s[i]);
66ExpandedSubBlockEnd.gif  }

67ExpandedBlockEnd.gif }

68 None.gif </ script >
2、aspx页面代码
 1  < select  id ="SelParent"  runat ="server"  onchange ="selectChange(this)" >
 2      < option  selected ="selected"  value ="0" > 请选择  </ option >
 3     </ select >
 4     < br  />
 5     < select  id ="SelSon"  runat ="server"  onchange ="selectChangeSon(this)" >
 6      < option  selected ="selected"  value ="0" > 请选择  </ option >
 7     </ select >
 8     < br  />
 9     < select  id ="Sel" >
10      < option  selected ="selected"  value ="0" > 请选择 </ option >
11     </ select >
3、服务器端代码
  1 None.gif  OracleConnection conn  =   new  OracleConnection( " Data Source=?;UID=?;PWD=? " );
  2 None.gif
  3 None.gif
  4 None.gif     protected   void  Page_Load( object  sender, EventArgs e)
  5 None.gif
  6 ExpandedBlockStart.gifContractedBlock.gif     dot.gif {
  7InBlock.gif
  8InBlock.gif        ParentBind();
  9InBlock.gif
 10ExpandedBlockEnd.gif    }

 11 None.gif
 12 None.gif
 13 None.gif     private   string  resualt;
 14 None.gif
 15 None.gif
 16 None.gif     private   void  ParentBind()
 17 None.gif
 18 ExpandedBlockStart.gifContractedBlock.gif     dot.gif {
 19InBlock.gif
 20InBlock.gif        string str = "select distinct(CID) from multimenu order by cid";
 21InBlock.gif
 22InBlock.gif        DataSet ds = ExecuteSql4Ds(str);
 23InBlock.gif
 24InBlock.gif        SelParent.DataSource = ds;
 25InBlock.gif
 26InBlock.gif        SelParent.DataTextField = "cid";
 27InBlock.gif
 28InBlock.gif        SelParent.DataBind();
 29InBlock.gif
 30ExpandedBlockEnd.gif    }

 31 None.gif
 32 None.gif     private   string  SonBind( string  e) // 绑定第二级
 33 None.gif
 34 ExpandedBlockStart.gifContractedBlock.gif     dot.gif {
 35InBlock.gif
 36InBlock.gif        string str = "select distinct(CCID) from multimenu where CID=" + e;
 37InBlock.gif
 38InBlock.gif        DataSet ds = ExecuteSql4Ds(str);
 39InBlock.gif
 40InBlock.gif        string s = "";
 41InBlock.gif
 42InBlock.gif        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
 43InBlock.gif
 44InBlock.gif            s += ds.Tables[0].Rows[i][0+ "|";
 45InBlock.gif
 46InBlock.gif        return s;
 47InBlock.gif
 48ExpandedBlockEnd.gif    }

 49 None.gif
 50 None.gif 
 51 None.gif
 52 None.gif     private   string  ChildBind( string  e) // 绑定第三级
 53 None.gif
 54 ExpandedBlockStart.gifContractedBlock.gif     dot.gif {
 55InBlock.gif
 56InBlock.gif        string str = "select distinct(CCCID) from multimenu where CCID=" + e;
 57InBlock.gif
 58InBlock.gif        DataSet ds = ExecuteSql4Ds(str);
 59InBlock.gif
 60InBlock.gif        string s = "";
 61InBlock.gif
 62InBlock.gif        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
 63InBlock.gif
 64InBlock.gif            s += ds.Tables[0].Rows[i][0+ "|";
 65InBlock.gif
 66InBlock.gif        return s;
 67InBlock.gif
 68ExpandedBlockEnd.gif    }

 69 None.gif
 70 None.gif 
 71 None.gif
 72 None.gif     private  DataSet ExecuteSql4Ds( string  str)
 73 None.gif
 74 ExpandedBlockStart.gifContractedBlock.gif     dot.gif {
 75InBlock.gif
 76InBlock.gif        OracleCommand cmd = new OracleCommand(str, conn);
 77InBlock.gif
 78InBlock.gif        OracleDataAdapter da = new OracleDataAdapter(cmd);
 79InBlock.gif
 80InBlock.gif        DataSet ds = new DataSet();
 81InBlock.gif
 82InBlock.gif        da.Fill(ds);
 83InBlock.gif
 84InBlock.gif 
 85InBlock.gif
 86InBlock.gif        return ds;
 87InBlock.gif
 88ExpandedBlockEnd.gif    }

 89 None.gif
 90 None.gif     void  ICallbackEventHandler.RaiseCallbackEvent(String eventArgument)
 91 None.gif
 92 ExpandedBlockStart.gifContractedBlock.gif     dot.gif {
 93InBlock.gif
 94InBlock.gif        if (eventArgument.Length == 1)//绑定第二级,我的数据库里分别是用1,11,111来代表三级,所以长度为一的就是一级,大家可以根据自己的需要把修改
 95InBlock.gif
 96ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 97InBlock.gif
 98InBlock.gif            string eventArgument1 = SonBind(eventArgument);
 99InBlock.gif
100InBlock.gif            resualt = eventArgument1;
101InBlock.gif
102ExpandedSubBlockEnd.gif        }

103InBlock.gif
104InBlock.gif        else
105InBlock.gif
106ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
107InBlock.gif
108InBlock.gif            string eventArgument2 = ChildBind(eventArgument);
109InBlock.gif
110InBlock.gif            resualt = eventArgument2;
111InBlock.gif
112ExpandedSubBlockEnd.gif        }

113InBlock.gif
114ExpandedBlockEnd.gif    }

115 None.gif
116 None.gif     string  ICallbackEventHandler.GetCallbackResult()
117 None.gif
118 ExpandedBlockStart.gifContractedBlock.gif     dot.gif {
119InBlock.gif
120InBlock.gif        return resualt;
121InBlock.gif
122ExpandedBlockEnd.gif    }

4、数据库脚本

 1  create   table  MULTIMENU
 2  (
 3    ID     NUMBER ( 2 not   null ,
 4    CID    NUMBER ( 2 not   null ,
 5    DSCT   VARCHAR2 ( 30 not   null ,
 6    CCID   NUMBER ( 2 ),
 7    CCCID  NUMBER ( 3 )
 8  )
 9 
10 

转载于:https://www.cnblogs.com/jeffery19830101/archive/2007/05/19/752357.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值