在dropdownlist中添加一个默认项“--请选择--”
我已经在dropdownlist中从数据库中添加了一些项:SqlCommandcmd=newSqlCommand("selectdistinctbmfromxsbd_yh...
我已经在dropdownlist中从数据库中添加了一些项:
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.DataBind();
conn.Close();
我想再向ddl_bm中添加一项“--请选择--”让它成为默认的项,代码怎么写? 展开
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.DataBind();
conn.Close();
我想再向ddl_bm中添加一项“--请选择--”让它成为默认的项,代码怎么写? 展开
展开全部
你应该这样写:
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);
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);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询