Selected clause in ListBox control throwing errors

wings9697

Member
Joined
Aug 27, 2007
Messages
23
Location
Washington, DC
Programming Experience
10+
Hi. My project is using ListBoxes to set values on my case entry form. But after I run the form, close it, and go back in, I get this

VB.NET:
'DropDownList3' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.ArgumentOutOfRangeException: 'DropDownList3' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

and when I check my code, I see this ....

VB.NET:
   <td style="width: 100px">
                        <asp:Label ID="Label25" runat="server" Font-Bold="True" Text="Photos?"></asp:Label><br />
                        <asp:DropDownList ID="DropDownList3" runat="server" 
                            SelectedValue='<%# Bind("case_photo", "{0}") %>'>
                            <asp:ListItem [U][B]Selected="True"[/B][/U] Value="1">Yes</asp:ListItem>
                            <asp:ListItem Value="0">No</asp:ListItem>
                        </asp:DropDownList></td>
                    <td style="width: 112px">

I take it out, run it again, and it puts it back in.... What gives....?

Can anybody tell me what is going on? Thanks in advance.....
 
Never mind...

The error is coming from the fact that the value mentioned is the table field the DropDownList is bound to. If you are using web form templates and don't use the LinkButton controls that the Item templates create for you, it disconnects the forms from the table, creating a NULL situation, and throws the error, because the DropDown can't write your selection to a NULL location. I found this out after I put two regular buttons on the form and couldn't connect to the table, and started getting these exceptions. When I went back to the LinkButtons, I was able to add to the tables....

If anyone can explain why this happens, please let me know.....

Thanks....
 
Back
Top