I have a ddl
C#
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.
C#
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


Marius VasileRank #785 · 2.9K reputationPosted Sep 25, 2023, 1:07 PM EDT
Removing the procedure from Page_Load and keeping it only under if(!IsPostBack) did the trick
Marius VasileRank #785 · 2.9K reputationPosted Sep 25, 2023, 1:02 PM EDT
View is