DropDownList Gets an Empty Choice

I have a dropdownlist populated with code directly from the database. But there is a choice point that does not matter at the bottom. How can I bind data from a database exclusively / completely to avoid getting this empty choice in the future?

   protected void DropDownList_OnDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
    {

        if (e.Row.RowType == DataControlRowType.Footer)
        {
            DropDownList ddlName = (DropDownList)e.Row.FindControl("ddlName");

            ddlName.DataSource = MyClass.NameList();
            ddlName.DataTextField = "Name";
            ddlName.DataValueField = "id";
            ddlName.DataBind();

        }
    }
+4
source share
2 answers

Try deleting your code declaration '<asp: DropDownList>' and enter it again. This will update your dropdown from scratch, clearing all its links when it is deleted. Your current drop-down list may use a link somewhere along the development of your project.

+1
source

, NameList() .

+1

Source: https://habr.com/ru/post/1533268/


All Articles