标签:
方法定义:
1 public static void InitDropDownList(DropDownList ddl, bool isAddTopItem, DropDownList ddlSub, object ddlDataSource, string ddlTextField, string ddlValueField) 2 { 3 ddl.DataSource = ddlDataSource; 4 ddl.DataTextField = ddlTextField; 5 ddl.DataValueField = ddlValueField; 6 ddl.DataBind(); 7 if (isAddTopItem) 8 ddl.Items.Insert(0, new ListItem("--All--", "0")); 9 if (ddlSub != null) 10 ddlSub.Items.Insert(0, new ListItem("--All--", "0")); 11 }
使用方式:
1 XXClass.InitDropDownList(ddlAvailableFieldEnter, false, null, new string[]{"field1","field2","field3"}, "", "");
使用DataSource绑定一维数组时,DataTextField只需绑定空字符串
标签:
原文地址:http://www.cnblogs.com/huangjianwu/p/4538820.html