DropDownList 绑定方法总结
方法一:
string Sql = "SELECT RoleName FROM Roles";
Database db = DatabaseFactory.CreateDatabase("DataConsole");
DBCommandWrapper dbc = db.GetSqlStringCommandWrapper(Sql);
DataSet ds = db.ExecuteDataSet(dbc);
this.DropDownList2.DataSource=ds.Tables["Roles"];
string[] s=new string[ds.Tables[0].Rows.Count];
for(int i=0;i<s.Length;i++)
{
s[i]=ds.Tables[0].Rows[i].ItemArray[0].ToString();
}
foreach(string ss in s)
{
DropDownList2.Items.Add(ss);
}
方法二:
string Sql = "SELECT RoleName FROM Roles";
Database db = DatabaseFactory.CreateDatabase("DataConsole");
DBCommandWrapper dbc = db.GetSqlStringCommandWrapper(Sql);
DataSet ds = db.ExecuteDataSet(dbc);
this.DropDownList2.DataSource = ds.Tables[0]. DefaultView;
this.DropDownList2. DataTextField = " RoleName "; / /类型为字符
/ /this. DropDownList.DataValueField = "列名"; 类型为value
14:10:14 DropDownList2.DataBind();