OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source=" + Server.MapPath(".\\App_Data\\mydatabase.mdb"));
string Sql = "SELECT * FROM Class ORDER BY Taxis,Id DESC";
OleDbDataAdapter cmd = new OleDbDataAdapter(Sql, conn);
DataSet ds = new DataSet();
cmd.Fill(ds,"Class");
this.DropDownList1.DataSource = ds.Tables["Class"].DefaultView;
DropDownList1.DataTextField = "Name";
DropDownList1.DataValueField = "Id";
DropDownList1.DataBind();
string Sql = "SELECT * FROM Class ORDER BY Taxis,Id DESC";
OleDbDataAdapter cmd = new OleDbDataAdapter(Sql, conn);
DataSet ds = new DataSet();
cmd.Fill(ds,"Class");
this.DropDownList1.DataSource = ds.Tables["Class"].DefaultView;
DropDownList1.DataTextField = "Name";
DropDownList1.DataValueField = "Id";
DropDownList1.DataBind();
添加
for (int i = 1; i <=3; i++)
{
LIstItem li = new ListItem("文字" + i, "值" + i); //ListItem 代表列表的一项
DropDownList.Items.Add(li); //Items属性维护了列表的项集合
}
{
LIstItem li = new ListItem("文字" + i, "值" + i); //ListItem 代表列表的一项
DropDownList.Items.Add(li); //Items属性维护了列表的项集合
}
获取选择项的Text。 DropDownList.SelectedItem.Text
获取选择项的Value。DropDownList.SelectedItem.Value
或者 DropDownList.SelectedValue