使用DataSource绑定一维数组时,DataTextField只需绑定空字符串

方法定义:

 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)