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

方法定义:

 public static void InitDropDownList(DropDownList ddl, bool isAddTopItem, DropDownList ddlSub, object ddlDataSource, string ddlTextField, string ddlValueField)
{
ddl.DataSource = ddlDataSource;
ddl.DataTextField = ddlTextField;
ddl.DataValueField = ddlValueField;
ddl.DataBind();
if (isAddTopItem)
ddl.Items.Insert(, new ListItem("--All--", ""));
if (ddlSub != null)
ddlSub.Items.Insert(, new ListItem("--All--", ""));
}

使用方式:

 XXClass.InitDropDownList(ddlAvailableFieldEnter, false, null, new string[]{"field1","field2","field3"}, "", "");
上一篇:【模拟】Codeforces 671B Robin Hood


下一篇:MySQL数据库中tinyint字段值为1,读取出来为true的问题