绑定

            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();


添加

for (int i = 1; i <=3; i++)
{
    LIstItem li = new ListItem("文字" + i, "值" + i); //ListItem 代表列表的一项
    DropDownList.Items.Add(li); //Items属性维护了列表的项集合
}

获取选择项的Text,使用DropDownList.SelectedItem.Text
获取选择项的Value,使用DropDownList.SelectedItem.Value
                    或者 DropDownList.SelectedValue

 

相关文章:

  • 2021-05-19
  • 2021-12-13
  • 2021-08-27
  • 2021-07-12
  • 2021-11-06
  • 2022-02-23
  • 2021-11-20
  • 2021-09-16
猜你喜欢
  • 2021-12-24
  • 2021-08-12
  • 2022-12-23
  • 2021-06-25
  • 2021-08-27
  • 2022-02-23
  • 2021-07-24
相关资源
相似解决方案