Error is ddlgvRooms’ has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value
I read a lot of people having issues with this particular problem but non of the fixes have worked for my case.I have tried a few different things such as setting appenddatabounditems=”true” also tried to set in the itemcollection a default null value.
Most of the forums post on this that I read were from a couple years ago im hoping they fixed this bug already and I am just overlooking something.
I am trying to get my cascading dropdownlist to work in a gridview edittemplate fields. I created these in my detailsview on insert everything works great.
MySetup
Basically I have a webmethod that has 2 functions getRooms and getJacks that are supposed to grab the data from the 2 datasets that I have created.The Datasets get their data from a couple of SQLSTOREDPROCEDURES.
My aspx page dropdownlist and AjaxCDDL looks like this
<EditItemTemplate>
<asp:DropDownList ID="ddlgvRooms" runat="server"
SelectedValue='<%# Bind("intRoom") %>'>
</asp:DropDownList> <asp:CascadingDropDownID="ddlgvRooms_CascadingDropDown"
runat="server"
Enabled="True"
TargetControlID="ddlgvRooms"
Category="Jack"
ServiceMethod = "GetRooms"
ServicePath = "CascadingDropDownRooms.asmx"
LoadingText = "[Loading Rooms...]"
PromptText="Please Select Room">
</asp:CascadingDropDown>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblgvRoom" runat="server" Text='<%# Eval("intRoom") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="JackNumber" SortExpression="intJack">
<EditItemTemplate>
<asp:DropDownList ID="ddlgvJacks" runat="server"
Height="20px" Width="125px">
</asp:DropDownList>
<asp:CascadingDropDown ID="ddlgvJack_CascadingDropDown"
runat="server"
Enabled="True"
Category="Jack"
ServiceMethod="GetJacks"
ServicePath="CascadingDropDownRooms.asmx"
TargetControlID="ddlgvJacks"
ParentControlID="ddlgvRooms"
LoadingText="[Loading Jacks...]"
PromptValue="Please Select A Jack">
</asp:CascadingDropDown>
</EditItemTemplate>
<WebMethod()> _
Public Function GetRooms(ByVal knownCategoryValues As String, ByVal category As String) As CascadingDropDownNameValue()
Dim roomAdapter As New dsRoomsTableAdapters.roomlistTableAdapter()
Dim roomValues As New List(Of CascadingDropDownNameValue)()
For Each row As DataRow In roomAdapter.GetAllRooms()
roomValues.Add(New CascadingDropDownNameValue(row("RoomName").ToString(), row("intRoom").ToString()))
Next
Return roomValues.ToArray()
End Function
<WebMethod()> _
Public Function GetJacks(ByVal knownCategoryValues As String, ByVal category As String) As CascadingDropDownNameValue()
Dim kv As StringDictionary = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)
Dim jackid As Integer
If ((Not kv.ContainsKey("Jack")) Or (Not Int32.TryParse(kv("Jack"), jackid))) Then
Return Nothing
End If
Dim jackAdapter As New dsRoomJacksTableAdapters.jacklistTableAdapter()
Dim jackValues As New List(Of CascadingDropDownNameValue)()
For Each row As DataRow In jackAdapter.GetJacksByRoomId(jackid)
jackValues.Add(New CascadingDropDownNameValue(row("JackNumber").ToString(), row("intJack").ToString()))
Next
Return jackValues.ToArray()
End Function
DropDownList ddlgvRoom = (DropDownList)GridView1.Rows[e.RowIndex].FindControl(“ddlgvRoom”);
string strgvRoom = ddlgvRoom.SelectedItem.Text.ToString();