ASP.NET 中dropdownlist的绑定问题

来源:百度知道 编辑:UC知道 时间:2024/05/21 12:49:54
SqlConnection con = new SqlConnection("server=.;database=login;uid=sa;pwd=;");
con.Open();
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter("select * from Met where usermet='" + Label11.Text + "'", con);
da.Fill(ds, "username");
DropDownList1.DataSource = ds;
DropDownList1.DataMember = "username";
DropDownList1.DataBind();

为什么总是显示再dropdownlist里面是“System.Data.DataRowView”???

把DropDownList1.DataMember = "username"; 改成DropDownList1.DataTextField = "username"; 就可以了

Sub DDLBind()
Dim tmpTab As DataTable = myDB.GetTab("select * from Dictionary order by ID")
CID.DataSource = tmpTab.DefaultView
CID.DataValueField = tmpTab.Columns("ID").ToString
CID.DataTextField = tmpTab.Columns("Name").ToString
CID.DataBind()
End Sub