protected void Page_Load(object sender, EventArgs e)
{
//skipped
foreach(pair item in al)
{
pid.Items.Add(new ListItem(item.getTitle(), item.getId()));
}
}
protected void Button1_Click(object sender, EventArgs e)
{
insertUser.Parameters.AddWithValue("@parent_id", Convert.ToInt32(pid.SelectedValue));
}
From the above code there is a dropdownlist that all items are added from Page_Load function, and the bug is that, whatever items i choose from dropdownlist, only the first item is added to database.
anyone know what’s the problem?
thanks!
You should not add items during postbacks
try
The IsPostBack property checks whether the page is being rendered for the first time or is responding to a postback.