title: How to fix "'ddlAssignedTo' has a SelectedValue which is invalid because it does not exist in the list of items
body: <p>I load the gridview and the gridview has an edit and delete buttons.</p>
  
  <p>I click on Edit and I get, "<code>ddlAssignedTo' has a SelectedValue which is invalid because it does not exist in the list of items.
  Parameter name: value</code></p>
  
  <p>I know that I am getting this error because the value fo <code>ddlAssignedTo</code> is null  - nothing  exists on the db for ddlAssignedTo. </p>
  
  <p>All I was trying to do is update the current value.</p>
  
  <p>So, my issue is this, if the current value is null, how do I assign a default value for ddlAssignedTo so that if no value currently exists on the db, the default value will prevail?</p>
  
  <p>Here are some code:</p>
  
  <p>Markup:</p>
  
  <pre><code>&lt;asp:TemplateField HeaderText="Assigned To"&gt;
      &lt;EditItemTemplate&gt;
        &lt;asp:DropDownList ID="ddlAssignedTo" runat="server" 
                          DataSourceID="SubjectDataSource"
                          DataTextField="fullname" DataValueField="empl_Id"
                          SelectedValue='&lt;%# Bind("AssignedTo") %&gt;'&gt;
          &lt;asp:ListItem Value=""&gt;--Select Name--&lt;/asp:ListItem&gt;
        &lt;/asp:DropDownList&gt;
      &lt;/EditItemTemplate&gt;
      &lt;ItemTemplate&gt;
          &lt;asp:Label ID="lblAssigned" runat="server" 
                     Text='&lt;% #Bind("fullname") %&gt;'&gt;&lt;/asp:Label&gt;
      &lt;/ItemTemplate&gt;
  &lt;/asp:TemplateField
  
  &lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                     ConnectionString="&lt;%$ ConnectionStrings:ConnectionString %&gt;"
                     SelectCommand="SELECT Distinct [rownum],[reqnum], AssignedTo, (empl_first + ' ' + empl_last) fullname, [reqrecdate], [reqrecfrom], [skillsets], [application], [hoursperweek], [fromdate], [todate], [status], [statusupdate], [statusupby] FROM [requestinfo] left join employee on requestInfo.AssignedTo=employee.empl_id ORDER BY [reqnum]" 
                     UpdateCommand="INSERT INTO [requestinfo] ([reqnum], [reqrecdate], [reqrecfrom], [skillsets], [application], [hoursperweek], [fromdate], [todate], [status], [statusupdate], [statusupby],[AssignedTo]) VALUES (@reqnum, @reqrecdate, @reqrecfrom, @skillsets, @application, @hoursperweek, @fromdate, @todate, @status, @statusupdate, @statusupby,@empl_id)"&gt;
      &lt;DeleteParameters&gt;
          &lt;asp:Parameter Name="rownum" Type="Int32" /&gt;
      &lt;/DeleteParameters&gt;
      &lt;UpdateParameters&gt;
          &lt;asp:Parameter Name="reqnum" Type="String" /&gt;
          &lt;asp:Parameter DbType="DateTime" Name="reqrecdate" /&gt;
          &lt;asp:Parameter Name="reqrecfrom" Type="String" /&gt;
          &lt;asp:Parameter Name="skillsets" Type="String" /&gt;
          &lt;asp:Parameter Name="application" Type="String" /&gt;
          &lt;asp:Parameter Name="hoursperweek" Type="Int32" /&gt;
          &lt;asp:Parameter DbType="DateTime" Name="fromdate" /&gt;
          &lt;asp:Parameter DbType="DateTime" Name="todate" /&gt;
          &lt;asp:Parameter Name="status" Type="String" /&gt;
          &lt;asp:Parameter DbType="DateTime" Name="statusupdate" /&gt;
          &lt;asp:Parameter Name="statusupby" Type="String" /&gt;
          &lt;asp:Parameter Name="empl_id" Type="String" /&gt;
          &lt;asp:Parameter Name="rownum" Type="Int32" /&gt;
      &lt;/UpdateParameters&gt;
  &lt;/asp:SqlDataSource&gt;
  &lt;asp:SqlDataSource ID="SubjectDataSource" runat="server" 
                     ConnectionString="&lt;%$ ConnectionStrings:ConnectionString %&gt;"
                     SelectCommand="SELECT empl_id,  (empl_first + ' ' + empl_last) fullname FROM dbo.Employee order by empl_last"&gt;
  &lt;/asp:SqlDataSource&gt;
  </code></pre>
  
  <p>CodeBehind:</p>
  
  <pre><code>Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs) Handles GridView1.RowUpdating
  
      Dim dd As DropDownList = DirectCast(GridView1.Rows(e.RowIndex).FindControl("ddlstatus"), DropDownList)
      e.NewValues("status") = dd.SelectedItem.Text
      Dim ddAssigned As DropDownList = DirectCast(GridView1.Rows(e.RowIndex).FindControl("ddlAssignedTo"), DropDownList)
  
      If String.IsNullOrEmpty(ddAssigned.SelectedValue) Then
          ddAssigned.SelectedValue = "shhhh"
      Else
          e.NewValues("empl_id") = ddAssigned.SelectedValue
      End If
  
      SqlDataSource1.DataBind()
  End Sub
  </code></pre>