title: GridView where clause
body: <p>I have an asp page where I am using a gridview to display some things. I have the grid view binded to a table in a database. The problem is I want to filter what I am displaying based on a where clause.</p>
  
  <pre><code>&lt;asp:LinqDataSource ID="ItemsDataSource" runat="server" ContextTypeName="Database.MyDataContext" TableName="ItemDetails" OnSelecting="ItemSourceSelecting" Where="ID == @ID" &gt;
  </code></pre>
  
  <p>Then here is my ItemSourceSelecting</p>
  
  <pre><code>protected void ItemSourceSelecting(object sender, LinqDataSourceSelectEventArgs e)
  {
      if (!IsPostBack)
          e.WhereParameters.Add("ID", ID);
  }
  </code></pre>
  
  <p>This works great when the page loads the first time I go to it. The problem is I am only displaying 10 items in the GridView and then it has the page numbers at the bottom. When I try to view another page it brings back everything in the database and doesn't call ItemSourceSelecting. Is there another place or way I should be doing this so this doesnt happen?</p>
  
  <p>Edit:
  It works fine when I hard code Where="ID == 1" in the LinqDataSource tag. It seems like it should be calling ItemSourceSelecting when changing pages but it is not. Somehow the where clause is getting thrown away when the page is being changed.</p>