1
protected
void
Page_Load(
object
sender, EventArgs e)
2
{
3
if (!IsPostBack)
4
{
5
GetAllDepartment();
6
GetAllOS();
7
}
8
}
9
10
public
void
GetAllDepartment()
11
{
12
dt = business.GetAllDepartment();
13
this.departmentListSelect.DataSource = dt;
14
this.departmentListSelect.DataValueField = dt.Columns[0].ColumnName;
15
this.departmentListSelect.DataTextField = dt.Columns[1].ColumnName;
16
this.departmentListSelect.Items.Insert(0, new ListItem("请选择", "0"));
17
}
18
19
public
void
GetAllOS()
20
{
21
dt = business.GetAllOS();
22
this.oSListSelect.DataSource = dt;
23
this.oSListSelect.DataValueField = dt.Columns[0].ColumnName;
24
this.oSListSelect.DataTextField = dt.Columns[1].ColumnName;
25
this.oSListSelect.Items.Insert(0, new ListItem("请选择", "0"));
26
}
结果最后才找到错误的原因所在.

2



3

4



5

6

7

8

9

10

11



12

13

14

15

16

17

18

19

20



21

22

23

24

25

26

在定义数据源后必须要"将数据源绑定到被调用的服务器控件及其所有子控件",所以少了一个DataBind()的过程.
在16行和25行后加入DataBind()即可解决。
有关DataBind()的参见:
http://msdn2.microsoft.com/zh-cn/library/system.web.ui.control.databind(VS.80).aspx