您的位置:首页 > 其它

ICallbackEventHandl 4000 er接口实现多级联动 (转)

2020-02-29 20:21 204 查看

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

 1  function CallServer()
 2   {
 3   var product = "测试";
 4   <%= ClientScript.GetCallbackEventReference(this, "product", "ReceiveServerData",null)%>;
 5  }
 6  
 7  function ReceiveServerData(rValue)
 8   {
 9   alert(rValue);
10   window.location.reload();
11   var tt=document.getElementById("TextBox1");
12   alert(tt.DataSource);
13  }
14  
15  function selectChange(e)
16   {
17   for(var i=0;i<e.options.length;i++)
18    {
19    if(e.options[i].selected==true)
20     {
21     selectSon(e.options[i].value); break;
22    }
23   }
24  }
25  
26  function selectSon(e) 
27   {
28   <%= ClientScript.GetCallbackEventReference(this, "e", "ReceiveServerData",null)%>;
29  }
30  
31  function ReceiveServerData(rValue)
32   {
33   var son=form1.elements["SelSon"];
34   var s=rValue.split("|");
35   son.length=s.length;
36   for(var i=0;i<s.length-1;i++)
37    {
38    son.options[i+1]=new Option(s[i],s[i]);
39   }
40  }
41  /////////////////////
42  function selectChangeSon(e)
43   {
44   for(var i=0;i<e.options.length;i++)
45    {
46    if(e.options[i].selected==true)
47     {
48     select(e.options[i].value); break;
49    }
50   }
51  }
52  
53  function select(e)
54   {
55   <%= ClientScript.GetCallbackEventReference(this, "e", "hello",null)%>;
56  }
57  
58  function hello(rValue)
59   {
60   var child=form1.elements["Sel"];
61   var s=rValue.split("|");
62   child.length=s.length;
63   for(var i=0;i<s.length-1;i++)
64    {
65    child.options[i+1]=new Option(s[i],s[i]);
66   }
67  }
68 </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  OracleConnection conn = new OracleConnection("Data Source=?;UID=?;PWD=?");
  2
  3
  4     protected void Page_Load(object sender, EventArgs e)
  5
  6      {
  7
  8         ParentBind();
  9
 10     }
 11
 12
 13     private string resualt;
 14
 15
 16     private void ParentBind()
 17
 18      {
 19
 20         string str = "select distinct(CID) from multimenu order by cid";
 21
 22         DataSet ds = ExecuteSql4Ds(str);
 23
 24         SelParent.DataSource = ds;
 25
 26         SelParent.DataTextField = "cid";
 27
 28         SelParent.DataBind();
 29
 30     }
 31
 32     private string SonBind(string e)//绑定第二级
 33
 34      {
 35
 36         string str = "select distinct(CCID) from multimenu where CID=" + e;
 37
 38         DataSet ds = ExecuteSql4Ds(str);
 39
 40         string s = "";
 41
 42         for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
 43
 44             s += ds.Tables[0].Rows[i][0] + "|";
 45
 46         return s;
 47
 48     }
 49
 50  
 51
 52     private string ChildBind(string e)//绑定第三级
 53
 54      {
 55
 56         string str = "select distinct(CCCID) from multimenu where CCID=" + e;
 57
 58         DataSet ds = ExecuteSql4Ds(str);
 59
 60         string s = "";
 61
 62         for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
 63
 64             s += ds.Tables[0].Rows[i][0] + "|";
 65
 66         return s;
 67
 68     }
 69
 70  
 71
 72     private DataSet ExecuteSql4Ds(string str)
 73
 74      {
 75
 76         OracleCommand cmd = new OracleCommand(str, conn);
 77
 78         OracleDataAdapter da = new OracleDataAdapter(cmd);
 79
 80         DataSet ds = new DataSet();
 81
 82         da.Fill(ds);
 83
 84  
 85
 86         return ds;
 87
 88     }
 89
 90     void ICallbackEventHandler.RaiseCallbackEvent(String eventArgument)
 91
 92      {
 93
 94         if (eventArgument.Length == 1)//绑定第二级,我的数据库里分别是用1,11,111来代表三级,所以长度为一的就是一级,大家可以根据自己的需要把修改
 95
 96          {
 97
 98             string eventArgument1 = SonBind(eventArgument);
 99
100             resualt = eventArgument1;
101
102         }
103
104         else
105
106          {
107
108             string eventArgument2 = ChildBind(eventArgument);
109
110             resualt = eventArgument2;
111
112         }
113
114     }
115
116     string ICallbackEventHandler.GetCallbackResult()
117
118      {
119
120         return resualt;
121
122     }

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

  • 点赞
  • 收藏
  • 分享
  • 文章举报
diankenlu8603 发布了0 篇原创文章 · 获赞 0 · 访问量 119 私信 关注
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: