User-640323567 posted
Hi, I have a gridview, which needs to show a total of distinct rows in a column. This can be shown in a label under the gridview.
Because there could be multiple same records with same product ids but with different other data, I need to show distinct count of products.
I have tried this way, but it shows only the count for the records in the current page. When I move to other page, the count reflects that particular page data.
protected void gdv_RowDataBound(object sender, GridViewRowEventArgs e)
{
var distinctRows = (from GridViewRow row in gdv.Rows
select row.Cells[1].Text
).Distinct().Count();
lblCount.Text = "Total number of records: " + distinctRows.ToString();
}
How do I show a distinct count of ALL the records in gridview irrespective of what page we are looking at?
In short, row.Cells[1] has product Ids which can contain duplicates and I want to extract distinct count of these product ids.
And I've set the pagesize as 15.
Thanks for any help!