方法定义:
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"}, "", "");