Punkcrib
08-29-2007, 11:38 PM
Hello. I have a seemingly simple problem that I cannot figure out.
I have 3 dropdownlists (Category, Subcategory, and Item). The Subcat. DDL is hidden until the 1st is changed by the user, and the Item DDL is hidden until the 2nd DDL is changed. Once the user selects an item from the "Item" DDL, a DetailView of the selected item becomes visible below the boxes. This is a very simple project so far.
Well My DDL's are pulling their items from a DB, and thus the 1st item of the list is automatically selected. This causes a problem when the list only contains 1 item, since there is no way to change that DDL's selectedvalue and cause an AutoPostBack.
So what I wanted to do was add a "blank" item to each DDL right before it's Visible parameter is changed to True. Well the 1st DDL is displayed with the page, so obviously this means I should place this code in the Page_Load function, right?
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
IF Not Page.IsPostBack Then
Me.DropDownList1.Items.Insert(0, new ListItem())
END IF
END SUB
So why isn't this working????????? The only thing I have been able to figure out is that if I remove the IF statement, then a blank line will ONLY be added to the DDL after a PostBack, and NOT on the initial Load. What is causing this? How do I get it to perform the statement on 1st load and not subsequently?
any help is much appreciated. I am pretty new to ASP.net and especially VB (I'm a Java guy, but my boss isn't, so that means I am not either:confused: ), but this seems relatively straight forward. yet I can't get it to work.
Thanks!
I have 3 dropdownlists (Category, Subcategory, and Item). The Subcat. DDL is hidden until the 1st is changed by the user, and the Item DDL is hidden until the 2nd DDL is changed. Once the user selects an item from the "Item" DDL, a DetailView of the selected item becomes visible below the boxes. This is a very simple project so far.
Well My DDL's are pulling their items from a DB, and thus the 1st item of the list is automatically selected. This causes a problem when the list only contains 1 item, since there is no way to change that DDL's selectedvalue and cause an AutoPostBack.
So what I wanted to do was add a "blank" item to each DDL right before it's Visible parameter is changed to True. Well the 1st DDL is displayed with the page, so obviously this means I should place this code in the Page_Load function, right?
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
IF Not Page.IsPostBack Then
Me.DropDownList1.Items.Insert(0, new ListItem())
END IF
END SUB
So why isn't this working????????? The only thing I have been able to figure out is that if I remove the IF statement, then a blank line will ONLY be added to the DDL after a PostBack, and NOT on the initial Load. What is causing this? How do I get it to perform the statement on 1st load and not subsequently?
any help is much appreciated. I am pretty new to ASP.net and especially VB (I'm a Java guy, but my boss isn't, so that means I am not either:confused: ), but this seems relatively straight forward. yet I can't get it to work.
Thanks!