1
using System;
2
using System.Data;
3
using System.Configuration;
4
using System.Web;
5
using System.Web.Security;
6
using System.Web.UI;
7
using System.Web.UI.WebControls;
8
using System.Web.UI.WebControls.WebParts;
9
using System.Web.UI.HtmlControls;
10
using System.Collections;
11
using System.Data.SqlClient;
12
using System.IO;
13
14
public partial class _Default : System.Web.UI.Page
15
{
16
protected void Page_Load(object sender, EventArgs e)
17
{
18
//构造数据源
19
//字符串数组
20
string[] DataSource1 = new string[] {"项目1","项目2","项目3" };
21
//哈西表
22
Hashtable DataSource2 = new Hashtable(3);
23
DataSource2.Add("项目1", "值1");
24
DataSource2.Add("项目2", "值2");
25
DataSource2.Add("项目3", "值3");
26
//数据集
27
DataSet DataSource3 = new DataSet();
28
string connString="server=.\\sqlexpress;database=Clients;uid=sa;pwd=123456;";
29
using (SqlConnection conn=new SqlConnection(connString))
30
{
31
SqlDataAdapter sda = new SqlDataAdapter("select * from OrderClient",conn);
32
sda.Fill(DataSource3);
33
}
34
//目录集合
35
DirectoryInfo di = new DirectoryInfo("D:\\");
36
DirectoryInfo[] DataSource4 = di.GetDirectories();
37
//动态数组
38
ArrayList DataSource5 = new ArrayList();
39
DataSource5.Add(new Link("谷歌","http://www.google.com"));
40
DataSource5.Add(new Link("百度","http://www.baidu.com"));
41
42
if (!IsPostBack)
43
{
44
//第一次请求
45
//绑定数据
46
DropDownList1.DataSource = DataSource1;
47
DropDownList1.DataBind();
48
DropDownList1.Items.Insert(0, "请选择");//放在DataBind方法之后,不然会被数据绑定覆盖
49
50
ListBox1.DataSource = DataSource2;
51
ListBox1.DataTextField = "key";
52
ListBox1.DataValueField = "value";
53
ListBox1.DataBind();
54
55
56
CheckBoxList1.DataSource = DataSource3;
57
CheckBoxList1.DataTextField = "ClientName";
58
CheckBoxList1.DataTextFormatString = "分类;{0}";
59
CheckBoxList1.DataValueField = "ClientID";
60
CheckBoxList1.DataBind();
61
62
RadioButtonList1.DataSource = DataSource4;
63
RadioButtonList1.DataTextField = "Name";
64
RadioButtonList1.DataValueField = "FullName";
65
RadioButtonList1.DataBind();
66
67
68
BulletedList1.DataSource = DataSource5;
69
BulletedList1.DataTextField = "Name";
70
BulletedList1.DataValueField = "Url";
71
BulletedList1.DataBind();
72
}
73
74
}
75
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
76
{
77
Response.Write(DropDownList1.SelectedValue);
78
}
79
protected void Button1_Click(object sender, EventArgs e)
80
{
81
foreach (ListItem li in ListBox1.Items)
82
{
83
if (li.Selected)
84
{
85
Response.Write(string.Format("{0}:{1}<br>",li.Text,li.Value));
86
}
87
}
88
}
89
protected void Button2_Click(object sender, EventArgs e)
90
{
91
foreach (ListItem li in CheckBoxList1.Items)
92
{
93
li.Selected = true;
94
}
95
}
96
protected void Button3_Click(object sender, EventArgs e)
97
{
98
foreach (ListItem li in CheckBoxList1.Items)
99
{
100
li.Selected = false;
101
}
102
}
103
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
104
{
105
Response.Write(RadioButtonList1.SelectedValue);
106
}
107
}
108
109
110
111
112
113
114
115
116
using System;
117
using System.Data;
118
using System.Configuration;
119
using System.Web;
120
using System.Web.Security;
121
using System.Web.UI;
122
using System.Web.UI.WebControls;
123
using System.Web.UI.WebControls.WebParts;
124
using System.Web.UI.HtmlControls;
125
126
/// <summary>
127
/// Link 的摘要说明
128
/// </summary>
129
public class Link
130
{
131
public Link(string Name,string Url)
132
{
133
this.Name = Name;
134
this.Url = Url;
135
}
136
137
private string name;
138
139
public string Name
140
{
141
get { return name; }
142
set { name = value; }
143
}
144
145
private string url;
146
147
public string Url
148
{
149
get { return url; }
150
set { url = value; }
151
}
152
}
153
using System;2
using System.Data;3
using System.Configuration;4
using System.Web;5
using System.Web.Security;6
using System.Web.UI;7
using System.Web.UI.WebControls;8
using System.Web.UI.WebControls.WebParts;9
using System.Web.UI.HtmlControls;10
using System.Collections;11
using System.Data.SqlClient;12
using System.IO;13

14
public partial class _Default : System.Web.UI.Page 15
{16
protected void Page_Load(object sender, EventArgs e)17
{18
//构造数据源19
//字符串数组20
string[] DataSource1 = new string[] {"项目1","项目2","项目3" };21
//哈西表22
Hashtable DataSource2 = new Hashtable(3);23
DataSource2.Add("项目1", "值1");24
DataSource2.Add("项目2", "值2");25
DataSource2.Add("项目3", "值3");26
//数据集27
DataSet DataSource3 = new DataSet();28
string connString="server=.\\sqlexpress;database=Clients;uid=sa;pwd=123456;";29
using (SqlConnection conn=new SqlConnection(connString))30
{31
SqlDataAdapter sda = new SqlDataAdapter("select * from OrderClient",conn);32
sda.Fill(DataSource3);33
}34
//目录集合35
DirectoryInfo di = new DirectoryInfo("D:\\");36
DirectoryInfo[] DataSource4 = di.GetDirectories();37
//动态数组38
ArrayList DataSource5 = new ArrayList();39
DataSource5.Add(new Link("谷歌","http://www.google.com"));40
DataSource5.Add(new Link("百度","http://www.baidu.com"));41

42
if (!IsPostBack)43
{44
//第一次请求45
//绑定数据46
DropDownList1.DataSource = DataSource1;47
DropDownList1.DataBind();48
DropDownList1.Items.Insert(0, "请选择");//放在DataBind方法之后,不然会被数据绑定覆盖49

50
ListBox1.DataSource = DataSource2;51
ListBox1.DataTextField = "key";52
ListBox1.DataValueField = "value";53
ListBox1.DataBind();54

55

56
CheckBoxList1.DataSource = DataSource3;57
CheckBoxList1.DataTextField = "ClientName";58
CheckBoxList1.DataTextFormatString = "分类;{0}";59
CheckBoxList1.DataValueField = "ClientID";60
CheckBoxList1.DataBind();61

62
RadioButtonList1.DataSource = DataSource4;63
RadioButtonList1.DataTextField = "Name";64
RadioButtonList1.DataValueField = "FullName";65
RadioButtonList1.DataBind();66

67

68
BulletedList1.DataSource = DataSource5;69
BulletedList1.DataTextField = "Name";70
BulletedList1.DataValueField = "Url";71
BulletedList1.DataBind();72
}73
74
}75
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)76
{77
Response.Write(DropDownList1.SelectedValue);78
}79
protected void Button1_Click(object sender, EventArgs e)80
{81
foreach (ListItem li in ListBox1.Items)82
{83
if (li.Selected)84
{85
Response.Write(string.Format("{0}:{1}<br>",li.Text,li.Value));86
}87
}88
}89
protected void Button2_Click(object sender, EventArgs e)90
{91
foreach (ListItem li in CheckBoxList1.Items)92
{93
li.Selected = true;94
}95
}96
protected void Button3_Click(object sender, EventArgs e)97
{98
foreach (ListItem li in CheckBoxList1.Items)99
{100
li.Selected = false;101
}102
}103
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)104
{105
Response.Write(RadioButtonList1.SelectedValue);106
}107
}108

109

110

111

112

113

114

115

116
using System;117
using System.Data;118
using System.Configuration;119
using System.Web;120
using System.Web.Security;121
using System.Web.UI;122
using System.Web.UI.WebControls;123
using System.Web.UI.WebControls.WebParts;124
using System.Web.UI.HtmlControls;125

126
/// <summary>127
/// Link 的摘要说明128
/// </summary>129
public class Link130
{131
public Link(string Name,string Url)132
{133
this.Name = Name;134
this.Url = Url;135
}136

137
private string name;138

139
public string Name140
{141
get { return name; }142
set { name = value; }143
}144

145
private string url;146

147
public string Url148
{149
get { return url; }150
set { url = value; }151
}152
}153



浙公网安备 33010602011771号