dal:
        public static DataSet getname()
        {
            string sql = "SELECT construction_id,name FROM construction";
            DataSet ds = new DataSet();      
            ds= DbHelperSQL.Query(sql);           
            return ds;
        }
bll:
        public static DataSet getname()
        {
            DataSet ds = asytj.DAL.construction.getname();
            return ds;
        }
页面:
前台
            <asp:DropDownList ID="DropDownList1" DataValueField="name" DataTextField="name"  runat="server">
        </asp:DropDownList>
后台:
         public void DataBind()
    {
        DropDownList ddl = new DropDownList();
        DataTable dt = new DataTable();
        ddl.DataSource = dt.DefaultView;
        ddl.DataValueField = "name";//显示的文字
        ddl.DataTextField = "name";//选项值
        ddl.DataBind();
    }
为什么老是没有数据啊?哪里错啦???

解决方案 »

  1.   

    DropDownList ddl = new DropDownList(); 
            DataTable dt = getname().Tables[0]; 
            ddl.DataSource = dt.DefaultView; 
            ddl.DataValueField = "name";//显示的文字 
            ddl.DataTextField = "name";//选项值 
            ddl.DataBind(); 
      

  2.   

    public void DataBind() 
        { 
            DropDownList ddl = new DropDownList(); 
            DataTable dt = new DataTable(); 
            ddl.DataSource = dt.DefaultView; 
            ddl.DataValueField = "name";//显示的文字 
            ddl.DataTextField = "name";//选项值 
            ddl.DataBind(); 
        } 
    你这里有调用你的BLL方法吗?
    不调用怎么会有数据
      

  3.   

    DataTable dt = getname().Tables[0]; 
    调方法
      

  4.   

      DropDownList ddl = new DropDownList(); 
            DataTable dt = new DataTable(); 
            ddl.DataSource = dt.DefaultView; 
            ddl.DataValueField = "name";//显示的文字 
            ddl.DataTextField = "name";//选项值 
            ddl.DataBind(); 
    dt没有赋值啊,怎么会有数据啊
    dt = getname().Table[0];
      

  5.   

        public void DataBind()
        {
            DropDownList ddl = new DropDownList();
            DataTable dt =asytj.BLL.construction.getname().Tables[0];
            ddl.DataSource = dt.DefaultView;
            ddl.DataValueField = "name";//显示的文字 
            ddl.DataTextField = "name";//选项值 
            ddl.DataBind();
        }
    还是没有数据
      

  6.   

    还有楼主,DropDownList ddl = new DropDownList(); 
    干嘛写这句了,
     DataTable dt = getname().Tables[0]; 
            DropDownList1.DataSource = dt.DefaultView; 
            DropDownList1.DataValueField = "name";//显示的文字 
            DropDownList1.DataTextField = "name";//选项值 
            DropDownList1.DataBind(); 
      

  7.   


    ddl 就没必要了吧? 直接用DropDownList1就可以了