日期:2014-05-19  浏览次数:20671 次

我想将数据绑定到dropdownlist中,可是下拉列表出现的是System.Data.....
为什么我用以下代码无法将数据绑定到下拉列表中呢?

private   void   Page_Load(object   sender,   System.EventArgs   e)
{
ConnectionString=System.Configuration.ConfigurationSettings.AppSettings[ "ConnectionString "];
conn=new   SqlConnection(ConnectionString);

if(!IsPostBack)
BindDropDownList();
}
private   void   BindDropDownList()
{
string   strsql;
strsql= "select   *   from   dep   ";
ds=new   DataSet();
da=new   SqlDataAdapter(strsql,conn);
conn.Open();
da.Fill(ds, "Dep ");
dep_name.DataSource=ds.Tables[0].DefaultView;
dep_name.DataBind();
conn.Close();    
}


------解决方案--------------------
指定DataValueField和DataTextField

DdlStorage.DataSource = storage_table;
DdlStorage.DataValueField = "STORAGE_ID ";
DdlStorage.DataTextField = "STORAGE_NAME ";
DdlStorage.DataBind();
------解决方案--------------------
dep_name.DataSource=ds.Tables[0].DefaultView;
//想在dropdownlist中显示的内容
dep_name.DataTextField = "XXX ";
//想在dropdownlist中保存的值的内容
dep_name.DataValueField = "YYY ";
dep_name.DataBind();



------解决方案--------------------
这样写行吗?
==============
这样应该可以了