I'm using Visual Studio 2005, VB... hope this is the right forum to post this question in.
I have multiple dropdownlists that are populated from a lookup table. In that lookup table, the user is allowed to flag an item as inactive so that it does not show up any longer in future drop down lists. The problem is that when a record is selected where the dropdownlist item is no longer active, it can't select a value from the dropdown list, throwing this error: "[dropdownlist] has a SelectedValue which is invalid because it does not exist in the list of items". In previous applications, I simply captured the fact that this was missing and then added it to the dropdownlist and then selected that value.
In this case, the dropdownlist is inside of a detailsview. I've been able to successfully build code that adds the item. Here's the essential part of that code:
(objDV is a DetailsView, DDName is the name of the dropdownlist in the DetailsView, and Value is the Item to be added to the list.)
If CType(objDV.FindControl(DDName), DropDownList).Items.FindByValue(Value) Is Nothing Then
CType(objDV.FindControl(DDName), DropDownList).Items.Add(Value)
CType(objDV.FindControl(DDName), DropDownList).SelectedValue = Value
End If
I've set this up on every single potential event (Page, DetailsView, DropDownList, DataSource for the DetailsView, DataSource for the DropDownList) and I've been able to verify that it works, checking the Item Count in the Immediate Window as I've stepped through my code but I always end up coming to the Page_Error event and the Item Count has dropped my new item before posting the error notice that I mentioned earlier. It appears that data is getting bound to the controls after I set the selected value, but I cannot seem to trap it in an event. What event is causing the dropdownlist to be reloaded, discarding my added item?
I have multiple dropdownlists that are populated from a lookup table. In that lookup table, the user is allowed to flag an item as inactive so that it does not show up any longer in future drop down lists. The problem is that when a record is selected where the dropdownlist item is no longer active, it can't select a value from the dropdown list, throwing this error: "[dropdownlist] has a SelectedValue which is invalid because it does not exist in the list of items". In previous applications, I simply captured the fact that this was missing and then added it to the dropdownlist and then selected that value.
In this case, the dropdownlist is inside of a detailsview. I've been able to successfully build code that adds the item. Here's the essential part of that code:
(objDV is a DetailsView, DDName is the name of the dropdownlist in the DetailsView, and Value is the Item to be added to the list.)
If CType(objDV.FindControl(DDName), DropDownList).Items.FindByValue(Value) Is Nothing Then
CType(objDV.FindControl(DDName), DropDownList).Items.Add(Value)
CType(objDV.FindControl(DDName), DropDownList).SelectedValue = Value
End If
I've set this up on every single potential event (Page, DetailsView, DropDownList, DataSource for the DetailsView, DataSource for the DropDownList) and I've been able to verify that it works, checking the Item Count in the Immediate Window as I've stepped through my code but I always end up coming to the Page_Error event and the Item Count has dropped my new item before posting the error notice that I mentioned earlier. It appears that data is getting bound to the controls after I set the selected value, but I cannot seem to trap it in an event. What event is causing the dropdownlist to be reloaded, discarding my added item?