日期:2014-05-18  浏览次数:20432 次

DropDownList1从数据库里面取出来的值,想在最前面加一个'请选择' 代码应该怎么改,谢谢.
void   DDlDate()
{
SqlConnection   con   =   new   SqlConnection(System.Configuration.ConfigurationSettings.AppSettings[ "Con "]);
con.Open();
SqlCommand   cmd   =   new   SqlCommand( "select   ToolID   from   nb_YiQiTool ",con);
SqlDataAdapter   sda   =   new   SqlDataAdapter(cmd);
DataSet   ds   =   new   DataSet();
sda.Fill(ds, "table1 ");
this.DropDownList1.DataSource=ds.Tables[ "table1 "].DefaultView;
this.DropDownList1.DataTextField= "ToolID ";//字段
this.DropDownList1.DataValueField= "ToolID ";
this.DropDownList1.DataBind();
}


------解决方案--------------------
手动加

然后设置属性 AppendDataBoundItems=true

然后就直接绑定好了
------解决方案--------------------
this.DropDownList1.DataBind(); 在这之后加: this.DropDownList1.Items.Insert(0,new ListItem( "请选择 ", " "));
------解决方案--------------------
DropDownList1.Items.Insert(0, " ");
------解决方案--------------------
dropAttribute.Items.Add( "------请选择------ ");
dropAttribute.Items.FindByText( "------请选择------ ").Selected = true;
dropAttribute.Items.FindByText( "------请选择------ ").Value = " ";
------解决方案--------------------
this.DropDownList1.Items.Insert(0,new ListItem( "--请选择-- ", " "));
this. DropDownList1.SelectedIndex = 0;
------解决方案--------------------
下拉框---编辑项---添加一个“请选择”,然后下拉框的属性里AppendDataBingItems设置为true