Click here to Skip to main content
15,799,183 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
protected void Page_Load(object sender, EventArgs e)
    if (!this.IsPostBack)
        string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
        using (SqlConnection con = new SqlConnection(constr))
            using (SqlCommand cmd = new SqlCommand
                   ("SELECT CustomerId, Name FROM Customers"))
                cmd.CommandType = CommandType.Text;
                cmd.Connection = con;
                ddlCustomers.DataSource = cmd.ExecuteReader();
                ddlCustomers.DataTextField = "Name";
                ddlCustomers.DataValueField = "CustomerId";
        ddlCustomers.Items.Insert(0, new ListItem("", ""));

What I have tried:

Dropdownlist items, if first item selected, then first item not display is Dropdownlist?
Updated 6-Oct-23 9:38am
Dave Kreskowiak 29-May-23 10:15am    
You're going to have to do more explaining of what you're talking about. What is "customerid1" and how does that relate to the database code you posted?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900