title: Gridview empty when SelectedIndexChanged called
body: <p>I have a DataGrid which is being bound dynamically to a database query. The user enters some search text into a text field, clicks search, and the code behind creates the appropriate database query using LINQ (searches a table based on the string and returns a limited set of the columns).</p>
  
  <p>It then sets the GridView datasource to be the query and calls DataBind().</p>
  
  <pre><code>protected void btnSearch_Click(object sender, EventArgs e)
  {
      var query = from record in DB.Table
                  where record.Name.Contains(txtSearch.Text) //Extra string checking etc. removed.
                  select new
                  {
                      record.ID,
                      record.Name,
                      record.Date
                  };
  
      gvResults.DataSource = query;
      gvResults.DataBind();
  }
  </code></pre>
  
  <p>This works fine.</p>
  
  <p>When a user selects a row in the grid, the SelectedIndexChanged event handler gets the id from the row in the grid (one of the fields), queries the full record from the DB and then populates a set of editor / details fields with the records full details.</p>
  
  <pre><code>protected void gvResults_SelectedIndexChanged(object sender, EventArgs e)
  {
      int id = int.Parse(gvResults.SelectedRow.Cells[1].Text);
      DisplayDetails(id);
  }
  </code></pre>
  
  <p>This works fine on my local machine where I'm developing the code. On the production server however, the function is called successfully, but the row and column count on <code>gvResults</code>, the griview is 0 - the table is empty.</p>
  
  <p>The gridview's viewstate is enabled and I can't see obvious differences. Have I made some naive assumptions, or am I relying on something that is likely to be configured differently in debug?</p>
  
  <p>Locally I am running an empty asp.net web project in VS2008 to make development quicker. The production server is running the sitecore CMS so is configured rather differently.</p>
  
  <p>Any thoughts or suggestions would be most welcome. Thanks in advance!</p>