How do you handle the ArgumentOutOfRangeException thrown from a DropDownList within a gridview? I have a editable field containing a DropDownList. The list is bind to a data source. Basically, the error is thrown because the item no longer exists in the list. When this exception occurs, I just want to set the selected value to something like "Not Applicable" which is a value that will always be in the list. Here is my code:
Code:
<asp:TemplateField HeaderText="Department" >
<ItemTemplate>
<asp:Label ID="lblDepartment" runat="server" Text='<%# Bind("Department") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddlDepartments" runat="server"
DataSourceID="ObjectDataSource2"
DataTextField="Department"
DataValueField="Department" OnDataBinding=""
SelectedValue='<%# Bind("Department") %>'>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>