Hi all,
I have written some code to do a bulk update of a gridview. In the gridview one of my template fields has a drop downlist:
<asp:DropDownList ID="DDLCategories" runat="server"
DataSourceID="odsCategories" DataTextField="txtCategory"
DataValueField="intCategoryID" SelectedValue='<%# Bind("intCategoryID") %>'>
<asp:ListItem Text="Please Select an item" Value ="-1"></asp:ListItem>
</asp:DropDownList>
In my database I have 800 records. However only a few of them have been assigned the value of "intCategoryID". The rest are NULL.
The whole reason of the bulk update is to update all of the "intCategoryID" fields and assign a category ID to each record.
Because not all od the "intCategoryID" have been assigned a value I am getting an error when I try to render the page. The dropdown list is failing. Here is the message:
'DDLCategories' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value
Is there a way I can assign the empty categories to the list item that has a value of "-1" I have created in the dropdownlist? IE If the "intCategoryID" ISNULL then have "Please Select an item" selected, otherwise select the selected value.
Thanks...