DropDownList peoblem !?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I am using DropDownList. Then, I am adding the DropDownList item from the
database and it is work. When I check the value of the items in the
Page_Load, it is appear without problem. The problem appears when
SelectedIndexChanged is active; the value of the item is always "1".

This is ASP.NET code:

<asp:DropDownList id="categoryDropDownList" runat="server"
DataTextField="name" DataValueField="id"></asp:DropDownList>

and this is my C# code (code behind):

private void Page_Load(object sender, System.EventArgs e) {
// Put user code to initialize the page here

DataTable categoryDataTable = sweCategory.SelectAll();
categoryDropDownList.DataSource = categoryDataTable;
categoryDropDownList.DataBind();
}
....
....
....
private void categoryDropDownList_SelectedIndexChanged(object sender,
System.EventArgs e) {
SqlString categoryId = categoryDropDownList.SelectedItem.Value;

this.addItemPanel.Visible = false;
this.doneLabel.Text = categoryId.ToString();
}

Any help please ?!?


Thanks
 
I solved the problem and this is the new code

private void Page_Load(object sender, System.EventArgs e) {
// Put user code to initialize the page here

if(!IsPostBack) {
DataTable categoryDataTable = sweCategory.SelectAll();
categoryDropDownList.DataSource = categoryDataTable;
categoryDropDownList.DataBind();

categoryDropDownList.Items.Insert(0, new ListItem("","0"));
}
}
 
Back
Top