title: LinqDataSource - filtering for null values
body: <p>I am writing an ASP.Net web application.  I have listview, it's datasource is a LinqDataSource.  In my database, I have a staff table and I am trying filter for records by their team using a dropdownlist.  This works fine, until I select "All" in the dropdownlist.  It returns all staff except for the ones where the teamID is null.  How can I return the records where teamID is null?</p>
  
  <p>This is my code:</p>
  
  <pre><code>&lt;asp:ListView ID="ListView1" runat="server" DataSourceID="ldsStaff" DataKeyNames="staffID"&gt;
  
      &lt;LayoutTemplate&gt;
  &lt;table&gt;
    &lt;tr&gt;
       &lt;th&gt;Name&lt;/th&gt;
       &lt;th&gt;Team&lt;/th&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
       &lt;td&gt;&amp;nbsp&lt;/td&gt;
       &lt;td&gt;&lt;asp:DropDownList ID="ddlTeamFilter" runat="server" DataSourceID="ldsTeams" DataTextField="Team" DataValueField="TeamID" AppendDataBoundItems="true" AutoPostBack="true"&gt;
          &lt;asp:ListItem Text="[All]" Value=""&gt;&lt;/asp:ListItem&gt;
           &lt;/asp:DropDownList&gt;
       &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr ID="itemPlaceHolder" runat="server"&gt;&lt;/tr&gt;
  &lt;/table&gt;
  &lt;/LayoutTemplate&gt;
  ....
  &lt;/asp:Listview&gt;
  
  &lt;asp:LinqDataSource ID="ldsStaff" runat="server" 
      ContextTypeName="ProjectDatabase.ProjectDatabaseUsersDataContext" OrderBy="name" 
      TableName="Staffs" EnableUpdate="True" Where="inService == @inService &amp;amp;&amp;amp; TeamID == @TeamID"&gt;
      &lt;WhereParameters&gt;
          &lt;asp:Parameter DefaultValue="true" Name="inService" Type="Boolean" /&gt;
          &lt;asp:ControlParameter ControlID="ctl00$ContentPlaceHolder1$ListView1$ddlTeamFilter" Name="TeamID" Type="Int32" PropertyName="SelectedValue"/&gt;
       &lt;/WhereParameters&gt;
  &lt;/asp:LinqDataSource&gt;
  </code></pre>
  
  <p>In my code behind I handle the LinqDataSource selecting event:</p>
  
  <pre><code>Private Sub ldsStaff_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LinqDataSourceSelectEventArgs) Handles ldsStaff.Selecting
      Dim ddl As DropDownList = CType(ListView1.FindControlRecursive("ddlTeamFilter"), DropDownList)
      If ddl.SelectedValue = "" Then
          e.WhereParameters.Remove("TeamID")
      End If
  </code></pre>
  
  <p>I thought that if I removed the whereparameter when the dropdownlist is "All" it would force it to return all the records, but it doesn't work.</p>
  
  <p>Please help!</p>
  
  <p>Thanks,
  Emma</p>