在dropdownlist中添加一个默认项“--请选择--”

2024-12-16 17:24:38
推荐回答(1个)
回答1:

你应该这样写:
SqlCommand cmd = new SqlCommand("select distinct bm from xsbd_yhdl",conn);
SqlDataReader dr = cmd.ExecuteReader();
this.ddl_bm.DataSource = dr;
this.ddl_bm.DataTextField = "bm";
this.ddl_bm.DataValueField="对应的值";
this.ddl_bm.DataBind();
conn.Close();
ListItem li= new ListItem("--请选择--", "");
this.ddl_bm.Items.Insert(0,li);