I have a Gridview that binds to an ObjectDataSource object (objStudentDetails). In the edit / paste mode of Gridview, one of the fields is DropDownList, which gets it from the list of the list from the search list. I have a DropDownList binding to another ObjectDataSource control (objStateList) that represents a lookup table. It works fine as long as the value in objStudentDetails ObjectDataSource matches one of the values in objStateList ObjectDataSource, at least in the case of a non-empty string value anyway.
objStateList has these values (from a stored proc that loads it - ID # 6 - empty string ''):
StateId State
----------- -----
6
4 AL
1 GA
3 KY
2 TN
objStudentDetails has these values (from a stored proc that loads it):
FirstName LastName State
----------- ---------- -----
tone smith TN
Or it may have this result set (State - empty string - ''):
FirstName LastName State
----------- ---------- -----
jenny johnson
In the first objStudentDetails result set, the state of the DropDownList in the EditItemTemplate is displayed in order. However, in the second result set, I get this error:
'ddlEditState' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value
I would think that since my lookup table has a value with an empty string, the value of objStudentDetails with an empty string for the state will match, but something does not work as I expect.
Here is my EditItemTemplate code from Gridview:
<EditItemTemplate>
<asp:Panel ID="panEditState" runat="server">
<asp:DropDownList ID="ddlEditState" runat="server" CssClass="GridviewDropdownlist"
DataSourceID="objStateList" DataTextField="State" DataValueField="State"
SelectedValue='<%# Bind("State") %>'
Width="50px">
</asp:DropDownList>
</asp:Panel>
</EditItemTemplate>
And objStateList, which calls the method that passes the parameter from which the lookup table is requested:
<asp:ObjectDataSource ID="objStateList" runat="server" SelectMethod="GetDropdownData" TypeName="AIMLibrary.BLL.DropdownData">
<SelectParameters>
<asp:Parameter Name="itemsToGet" DefaultValue="state" />
</SelectParameters>
</asp:ObjectDataSource>
Any ideas?