如何将DropDownList中的第一项置于空白处?在VB中是这样的,DropDownList.index [0] =“”; 我这样做:Dropdownlist中的第一项空白
string StrConn = ConfigurationManager.ConnectionStrings["connSql"].ConnectionString;
SqlConnection conn = new SqlConnection(StrConn);
conn.Open();
SqlDataReader dr;
string sql;
sql = @"Select Nome From DanielPessoas";
SqlCommand cmd = new SqlCommand(sql, conn);
dr = cmd.ExecuteReader();
DropDownList1.DataSource = dr;
DropDownList1.DataTextField = "Nome";
DropDownList1.DataValueField = "Nome";
DropDownList1.DataBind();
打我吧。我建议的唯一的事情是为空白选择设置一些值,以便验证或选择值检查更容易。 – 2009-07-02 16:37:28
如果您使用string.empty /“”作为值,那么您可以使用RequiredFieldValidator。不过,我会建议在“Select ...”这样的文本字段中加入一些东西。 – 2009-07-02 16:40:04