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).
It then sets the GridView datasource to be the query and calls DataBind().
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();
}
This works fine.
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.
protected void gvResults_SelectedIndexChanged(object sender, EventArgs e)
{
int id = int.Parse(gvResults.SelectedRow.Cells[1].Text);
DisplayDetails(id);
}
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 gvResults
, the griview is 0 - the table is empty.
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?
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.
Any thoughts or suggestions would be most welcome. Thanks in advance!