title: Gridview EditTemplate DropDownlist
body: <p>Error is <strong>ddlgvRooms' has a SelectedValue which is invalid because it does not exist in the list of items.
  Parameter name: value</strong></p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p><strong>MySetup</strong>
  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.</p>
  
  <p><strong>My aspx page dropdownlist and AjaxCDDL looks like this</strong> </p>
  
  <pre><code>  &lt;EditItemTemplate&gt;
                         &lt;asp:DropDownList ID="ddlgvRooms" runat="server"
                              SelectedValue='&lt;%# Bind("intRoom") %&gt;'&gt;  
                       &lt;/asp:DropDownList&gt;                                               &lt;asp:CascadingDropDownID="ddlgvRooms_CascadingDropDown"                 
                           runat="server"
                           Enabled="True" 
                           TargetControlID="ddlgvRooms" 
                           Category="Jack"
                           ServiceMethod = "GetRooms"
                           ServicePath = "CascadingDropDownRooms.asmx"
                           LoadingText = "[Loading Rooms...]"
                           PromptText="Please Select Room"&gt; 
                          &lt;/asp:CascadingDropDown&gt;
                      &lt;/EditItemTemplate&gt;
                      &lt;ItemTemplate&gt;
                          &lt;asp:Label ID="lblgvRoom" runat="server"                      Text='&lt;%#  Eval("intRoom") %&gt;'&gt;&lt;/asp:Label&gt;
                      &lt;/ItemTemplate&gt;
                  &lt;/asp:TemplateField&gt;
                  &lt;asp:TemplateField HeaderText="JackNumber" SortExpression="intJack"&gt;
                      &lt;EditItemTemplate&gt;
                          &lt;asp:DropDownList ID="ddlgvJacks" runat="server"
                          Height="20px" Width="125px"&gt;
  
                          &lt;/asp:DropDownList&gt;
                         &lt;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"&gt;
                          &lt;/asp:CascadingDropDown&gt;
  
                      &lt;/EditItemTemplate&gt;
  </code></pre>
  
  <hr>
  
  <pre><code>&lt;WebMethod()&gt; _
      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
  
          &lt;WebMethod()&gt; _
          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
  </code></pre>