Asp.net 2.0 一个简单的联动DropDownList示例(示例代码下载) [zhuan :D]
Posted on 2006-12-22 01:47 桦林 阅读(675) 评论(0) 编辑 收藏 举报(一). 示例图片
![](http://p.blog.csdn.net/images/p_blog_csdn_net/ChengKing/LinkageDDL.jpg)
(二). 详细代码
1. 页面前台代码
1
<body>
2
<form id="form1" runat="server">
3
<div>
4
<asp:Panel ID="Panel2" runat="server" BackColor="#FFC080" Font-Size="X-Large"
5
ForeColor="#C04000" Height="50px" Width="387px">
6
DropDownList 联动示例:</asp:Panel>
7
<asp:Panel ID="Panel1" runat="server" BackColor="#C0C0FF" Height="170px" Width="387px">
8
<br />
9
请选择类别:<br />
10
<br />
11
12
<asp:DropDownList ID="ddl1" runat="server">
13
</asp:DropDownList>
14
<asp:DropDownList ID="ddl2" runat="server">
15
</asp:DropDownList>
16
<asp:DropDownList ID="ddl3" runat="server">
17
</asp:DropDownList> <br />
18
<br />
19
20
<C1:RelatedList id="rl1" runat="server"></C1:RelatedList>
21
<asp:Button ID="btOK" runat="server" OnClick="Button1_Click" Text="取值" Width="67px" />
22
</asp:Panel>
23
</div>
24
</form>
25
</body>
26![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
7
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
8
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
9
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
10
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
11
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
12
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
13
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
14
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
15
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
16
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
17
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
18
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
19
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
20
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
21
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
22
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
23
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
24
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
25
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
26
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2.页面后台代码
1
protected void Page_Load(object sender, EventArgs e)
2
{
3
if (!Page.IsPostBack)
4
{
5
ArrayList Category = new ArrayList();
6
Category.Add("ddl1");
7
Category.Add("ddl2");
8
Category.Add("ddl3");
9![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
10
//Method 1. 指定XML文件路径
11
rl1.DataSource = @"Category.xml";
12![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
13
////Method 2. 指定数据源为DataSet对象
14
//DataSet ds = new DataSet();
15
//ds = GetData();
16
//rl1.DataSource = ds;
17![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
18![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
19
rl1.ListID = Category;
20
rl1.DataBind();
21![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
22
}
23
}
24
private DataSet GetData()
25
{
26
DataSet ds = new DataSet();
27
DataTable dt = new DataTable();
28
dt.Columns.Add(new DataColumn("Value", typeof(int)));
29
dt.Columns.Add(new DataColumn("Context", typeof(string)));
30
dt.Columns.Add(new DataColumn("ParentValue", typeof(int)));
31
DataRow drNew = dt.NewRow();
32
drNew["Value"] = 1;
33
drNew["Context"] = "水果";
34
drNew["ParentValue"] = 0;
35
dt.Rows.Add(drNew);
36![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
37
drNew = dt.NewRow();
38
drNew["Value"] = 2;
39
drNew["Context"] = "动物";
40
drNew["ParentValue"] = 0;
41
dt.Rows.Add(drNew);
42![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
43
drNew = dt.NewRow();
44
drNew["Value"] = 3;
45
drNew["Context"] = "葡萄";
46
drNew["ParentValue"] = 1;
47
dt.Rows.Add(drNew);
48![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
49
drNew = dt.NewRow();
50
drNew["Value"] = 7;
51
drNew["Context"] = "红葡萄";
52
drNew["ParentValue"] = 3;
53
dt.Rows.Add(drNew);
54![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
55
drNew = dt.NewRow();
56
drNew["Value"] = 8;
57
drNew["Context"] = "柴葡萄";
58
drNew["ParentValue"] = 3;
59
dt.Rows.Add(drNew);
60![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
61
drNew = dt.NewRow();
62
drNew["Value"] = 4;
63
drNew["Context"] = "桔子";
64
drNew["ParentValue"] = 1;
65
dt.Rows.Add(drNew);
66![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
67
drNew = dt.NewRow();
68
drNew["Value"] = 12;
69
drNew["Context"] = "红桔子";
70
drNew["ParentValue"] = 4;
71
dt.Rows.Add(drNew);
72![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
73
drNew = dt.NewRow();
74
drNew["Value"] = 13;
75
drNew["Context"] = "绿桔子";
76
drNew["ParentValue"] = 4;
77
dt.Rows.Add(drNew);
78![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
79
drNew = dt.NewRow();
80
drNew["Value"] = 5;
81
drNew["Context"] = "香蕉";
82
drNew["ParentValue"] = 1;
83
dt.Rows.Add(drNew);
84![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
85
drNew = dt.NewRow();
86
drNew["Value"] = 14;
87
drNew["Context"] = "马";
88
drNew["ParentValue"] = 2;
89
dt.Rows.Add(drNew);
90![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
91
drNew = dt.NewRow();
92
drNew["Value"] = 15;
93
drNew["Context"] = "红马";
94
drNew["ParentValue"] = 14;
95
dt.Rows.Add(drNew);
96![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
97
drNew = dt.NewRow();
98
drNew["Value"] = 16;
99
drNew["Context"] = "白马";
100
drNew["ParentValue"] = 14;
101
dt.Rows.Add(drNew);
102![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
103
drNew = dt.NewRow();
104
drNew["Value"] = 17;
105
drNew["Context"] = "蓝马";
106
drNew["ParentValue"] = 14;
107
dt.Rows.Add(drNew);
108![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
109
drNew = dt.NewRow();
110
drNew["Value"] = 18;
111
drNew["Context"] = "牛";
112
drNew["ParentValue"] = 2;
113
dt.Rows.Add(drNew);
114![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
115
ds.Tables.Add(dt);
116
return ds;
117
}
118
protected void Button1_Click(object sender, EventArgs e)
119
{
120
Response.Write("<script>alert('" + this.ddl1.SelectedItem.Text + "," + this.ddl2.SelectedItem.Text + "," +
121
this.ddl3.SelectedItem.Text + "');</script>");
122
}
123![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
7
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
8
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
9
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
10
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
11
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
12
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
13
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
14
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
15
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
16
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
17
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
18
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
19
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
20
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
21
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
22
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
23
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
24
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
25
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
26
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
27
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
28
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
29
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
30
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
31
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
32
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
33
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
34
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
35
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
36
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
37
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
38
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
39
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
40
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
41
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
42
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
43
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
44
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
45
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
46
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
47
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
48
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
49
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
50
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
51
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
52
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
53
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
54
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
55
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
56
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
57
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
58
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
59
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
60
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
61
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
62
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
63
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
64
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
65
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
66
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
67
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
68
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
69
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
70
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
71
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
72
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
73
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
74
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
75
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
76
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
77
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
78
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
79
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
80
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
81
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
82
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
83
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
84
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
85
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
86
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
87
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
88
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
89
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
90
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
91
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
92
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
93
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
94
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
95
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
96
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
97
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
98
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
99
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
100
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
101
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
102
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
103
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
104
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
105
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
106
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
107
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
108
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
109
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
110
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
111
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
112
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
113
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
114
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
115
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
116
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
117
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
118
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
119
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
120
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
121
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
122
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
123
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
(三).示例代码下载