我有一个从数据库填充的下拉列表。当我想在下拉列表的 DataTextField 中只显示名字时,我让它工作。但是如果我想显示 2 个字段,名字和姓氏,那么它会引发错误。为什么这不起作用或我怎样才能让它起作用?
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConString"].ConnectionString);
SqlCommand cmd = new SqlCommand("SELECT * FROM tbl_customers", con);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
con.Open();
da.Fill(ds, "Customers");
CustomerList.DataSource = ds.Tables[0];
CustomerList.DataTextField = "FirstName" + " " + "LastName";
CustomerList.DataValueField = "CID";
CustomerList.DataBind();