Dropdownlist中的第一项空白(First Item on Dropdownlist in blank)
如何将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();How to put the first item on the DropDownList in blank ? In VB is something like, DropDownList.index[0] = ""; I did this:
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));After your DataBind call, add this code.
DropDownList1.Items.Insert(0, new ListItem(string.Empty, string.Empty));更多推荐
发布评论