方法一:
使用属性设置,我们在DropDownList的items的属性中添加一列为空行,然后更改AppandBataBoundItems属性为ture.
绑定代码:


1

2

3

4

5

6

7

8

9



这样就可以了。
方法二:
使用代码:
1
2
SqlConnection conn
=
new
SqlConnection(
"
server=.;uid=sa;database=pubs
"
);
3
SqlDataAdapter dap
=
new
SqlDataAdapter(
"
select * from jobs
"
, conn);
4
DataTable dt
=
new
DataTable();
5
dap.Fill(dt);
6
DropDownList1.Items.Clear();
7
DropDownList1.DataSource
=
dt;
8
DropDownList1.DataTextField
=
"
job_desc
"
;
9
DropDownList1.DataValueField
=
"
job_id
"
;
10
DropDownList1.DataBind();
11
DropDownList1.Items.Insert(
0
,
new
ListItem(
""
,
""
));
//
插入空项,此举必须放到数据绑定之后
效果:

2

3

4

5

6

7

8

9

10

11

