Marius Vasile

Marius Vasile

  • 594
  • 1.9k
  • 144.8k

Dropdown list acting strange - duplicating same values

Sep 25 2023 4:54 PM

I have a ddl 

protected void LoadCodCompartiment()
{
    using (SqlConnection conn = new SqlConnection(connString))
    {
        string sqlQuery = "SELECT DISTINCT CodCompartiment FROM tblUser";
        using (SqlCommand cmd = new SqlCommand(sqlQuery, conn))
        {
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            conn.Open();
            DataSet ds = new DataSet();
            da.Fill(ds);
            ddlCompartiment.DataSource = ds;
            ddlCompartiment.DataBind();
        }
    }
}

which is loaded at Page_Load.

protected void Page_Load(object sender, EventArgs e)
{
    
    LoadCodCompartiment();
    

    if(!IsPostBack)
    {
        LoadCodCompartiment();
    }
}

The proble I have is that on first load the values are duplicated

and after I select one value and click on the dropdown again, values are multiplied

I don't understand why is doing so


Answers (2)