DataTable dt = new DataTable();
        DAL.Exec.Exec_YSBiz10_Dim_Area exec_YSBiz10_Dim_Area = new DAL.Exec.Exec_YSBiz10_Dim_Area();
        dt= exec_YSBiz10_Dim_Area.tb();
        this.DropDownList1.DataSource = dt;
        this.DropDownList1.DataTextField = "AreaName";
        this.DropDownList1.DataValueField = "AreaID";
        this.DropDownList1.DataBind();
        this.DropDownList1.Items.Insert(0,"所有省份");给下拉框的值附一个初始值:
this.DropDownList1.SelectedItem.Text = "";
代码报错请问怎么做啊

解决方案 »

  1.   

    new 一个ListItem,然后设置它的text,然后DropDownList1。Items。add(listitem)
      

  2.   

    DropDownList1.Items.Insert(0,new ListItem("所有省份",""));
    DropDownList1.SelectedValue="";
      

  3.   

    string city="";
    city = this.DropDownList1.SelectedItem.Text.ToString();
    报错信息,说未将对象引用,请问怎么回事
      

  4.   


    试试:
    city = this.DropDownList1.SelectedItem.Text;
      

  5.   


    DropDownList1.SelectedIndex=-1;//先去除已选项,一个DropDownList不能有两个已选项
    DropDownList1.SelectedValue="";//
      

  6.   

    DropDownList1.DataSource = dt;
    DropDownList1.DataTextField = "cl_name";
    DropDownList1.DataValueField = "cl_parent";
    DropDownList1.DataBind();DropDownList1.Items.Insert(0, "所有内容");
      

  7.   

    你查询出来的结果没有值,table是空的
      

  8.   

    因为没有 this.DropDownList1.SelectedItem.Text = " 的值  5楼可以解决你的问题
      

  9.   

    DropDownList1.SelectedValue="";  这个就可以
      

  10.   

    给下拉框的值附一个初始值:
    this.DropDownList1.SelectedItem.Text = ""; //这个好像没什么意义吧,只会把你的后面添加的 所有省份 这项直接变成""我试了下,代码这样写没有错,只不过它会把你选择的项的TEXT值设成空了.
    应该还是你前面绑定代码的问题
    你设断点踊跃调试下!