ASP.NET整理:DrpDownList,用法,…

来源:互联网 发布:java web学生信息修改 编辑:程序博客网 时间:2024/06/07 07:27

十六.DropDownList

属性:

AutoPostBack:在做DataList排序的时候会用到

DataTextField

DataValueField

SelectedIndex

SelectedItem

SeletedValue<==>SeletectedItem.Value

事件:

SelectedIndexChanged

往控件内添加数据:

1.通过代码添加:

for(int i=0;i<5;i++)

{

//第一个参数:DataTextField

//第二个参数:DataValueField

ListItem li new ListItem("item"+i,i.toString());

this.dropDownList1.Items.Add(li);

}

 

2.通过指定数据源进行添加:

this.dropDownList.DataSource new AA().SelectItems();

this.dropDownList.DataTextField "name";

this.dropDownList..DataValueField "uid";

this.dropDownList.DataBind();

this.dropDownList.Items.Insert(0,new ListItem("请选择","-1"));//Insert插入而不是Add,另外这一操作是在绑定后进行,意为在索引为0(即第一个)的地方插入一个ListItem

我的更多文章:
  • (2012-09-08 13:09:19)
  • (2012-09-08 13:09:05)
  • (2012-09-08 13:04:14)
  • (2012-09-08 12:54:54)
  • (2012-09-08 12:52:01)
  • (2012-09-08 12:48:53)
  • (2012-09-08 12:46:40)
  • (2012-09-03 20:54:24)
  • (2012-09-02 12:48:05)
  • (2012-07-26 15:42:32)