我们在进行数据绑定时通常把一个表的某个字段绑定到DropDownList中,我们以pubs库的jobs表为例子,我们在显示时显示job_desc字段,values值绑定job_id字段。
方法一:
使用属性设置,我们在DropDownList的items的属性中添加一列为空行,然后更改AppandBataBoundItems属性为ture.
绑定代码:
        DropDownList1.DataBind();

DropDownList数据绑定第一项为空(转)

DropDownList数据绑定第一项为空(转)

这样就可以了。
方法二:
使用代码:

 

插入空项,此举必须放到数据绑定之后

效果:
DropDownList数据绑定第一项为空(转)

 

相关文章:

  • 2022-12-23
  • 2021-06-12
  • 2021-10-26
  • 2022-12-23
  • 2022-12-23
  • 2022-03-03
  • 2021-09-04
  • 2022-12-23
猜你喜欢
  • 2021-07-29
  • 2021-08-27
  • 2022-02-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-19
相关资源
相似解决方案