如何将 DropDownList 上的第一项设为空白?在 VB 中类似于,DropDownList.index[0] = ""; 我这样做了:
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();
最佳答案
在 DataBind 调用之后,添加此代码。
DropDownList1.Items.Insert(0, new ListItem(string.Empty, string.Empty));
关于asp.net - 下拉列表中的第一项为空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1075390/