I’m getting different results displaying in my gridview than what appear when I debug.
Theres a search for a gridview which filters results and it only seems to work if numbers are under a few hundred.
Example, search for rank, where rank =='10' results in the stored procedure total 607 with all rank == 10. linq to sql results are exactly the same debugging.
when the results are bound to the gridview and displayed they appear to be correct until you get to page 10 of the results displayed and then the results are not correct, meaning the rank != 10
The results appear correct for smaller result sets.. not sure what’s going on.
here’s code
DataTable getEmployeeResults = employee.FullEmployeeRoster();
var results = (from row in getEmployeeResults.AsEnumerable()
select new EmployeeRow
{
EmployeeId = row.Field<int?>("EmployeeID"),
Rank = row.Field<string>("Rank"),
Name = row.Field<string>("Name"),
WorkEmail = row.Field<string>("Email"),
DutyStation = row.Field<string>("StationName"),
Directorate = row.Field<string>("Directorate"),
BranchService = row.Field<string>("Branch"),
Active = ConvertToBool(row.Field<int>("Active"))
});
if (this.ddRank.SelectedValue != "")
{
results = results.Where(x => x.Rank == this.ddRank.SelectedItem.Text);
}
if (this.chkInactive.Checked)
{
results = results.Where(x => x.Active == false);
}
else
{
results = results.Where(x => x.Active == true);
}
this.gridEmployees.DataSource = results.ToList();
this.gridEmployees.DataBind();
It is difficult to give a good answer here as the information provided is a bit unclear.
I assume that the FullEmployeeRoster is the stored procedure that returns 607 records with all rank == 10. At least that’s what I gather from your description. If so, then why filtering by 10? However, if it returns all records then it could be filtering issue.
Since it is IEnumerable we can rule out possible problems with SQL.
Then to troubleshoot I would first output all results at once, preferably on page_load. Either disable pagination or simply iterate over all records with foreach and write them to response. That way you will know for sure if what comes back at runtime is what you need and eliminate possible issues with the grid and postbacks.
Then I would check your pagination. Since it appears that you rely on a view state to do the pagination for you, I would make sure to check the size of it. The default max request length for post in .NET is set to 4MB (maxRequestLength = 4,096) yet it is conceivable that your web server is configured with a lesser value. That could corrupt it somehow. Although I think you’d be getting an exception in that case.
Finally, I would disable the view state and instead retrieve all data on each pagination and simply do .Skip(…).Take(…). But I have a feeling there is missing information somewhere in your post.