I got this working on for my dropdownlist populated on page load - very easy.
However, I'm having difficulty when a change is made after page load. I have two dropdown lists: hardware category and hardware sub category. When the category is changed, I pull a stored procedure that populates the second dropdown list with appropriate selections. Some categories do not have sub categories.
What I am trying to do is print "N/A" as the selected item in the dropdownlist when no items are returned, or "Not selected" as the selected field when there are items.
If Not (dr.Read()) Then
ddlTypeSub.Items.Insert(0, "N/A"
ddlTypeSub.SelectedIndex = 0
ddlTypeSub.SelectedItem.Value = 0
ddlTypeSub.SelectedItem.Text = "N/A"
dr.Close()
Else
ddlTypeSub.Items.Insert(0, "not selected"
ddlTypeSub.SelectedIndex = 0
ddlTypeSub.SelectedItem.Value = 0
ddlTypeSub.SelectedItem.Text = "not selected"
dr.Close()
End If
However, the sub category box returns the selected item "N/A" regardless of whether there are sub category items returned for the category selected. I tried placing "If Not page.IsPostBack" around the page load calls that populate these dropdown lists, but that didn't make a difference. It's probably a dumb error somewhere - can anyone offer any advice to lessen my mental anguish?
Thanks,
John
However, I'm having difficulty when a change is made after page load. I have two dropdown lists: hardware category and hardware sub category. When the category is changed, I pull a stored procedure that populates the second dropdown list with appropriate selections. Some categories do not have sub categories.
What I am trying to do is print "N/A" as the selected item in the dropdownlist when no items are returned, or "Not selected" as the selected field when there are items.
If Not (dr.Read()) Then
ddlTypeSub.Items.Insert(0, "N/A"
ddlTypeSub.SelectedIndex = 0
ddlTypeSub.SelectedItem.Value = 0
ddlTypeSub.SelectedItem.Text = "N/A"
dr.Close()
Else
ddlTypeSub.Items.Insert(0, "not selected"
ddlTypeSub.SelectedIndex = 0
ddlTypeSub.SelectedItem.Value = 0
ddlTypeSub.SelectedItem.Text = "not selected"
dr.Close()
End If
However, the sub category box returns the selected item "N/A" regardless of whether there are sub category items returned for the category selected. I tried placing "If Not page.IsPostBack" around the page load calls that populate these dropdown lists, but that didn't make a difference. It's probably a dumb error somewhere - can anyone offer any advice to lessen my mental anguish?
Thanks,
John