//Hello i can't write entiry code. beacuse i don't have asp.net web application. i have only vc# in my P.C.
// but i can give some idea.easily you can able to do ..
var groupby = dt.AsEnumerable().GroupBy(g => g.Field<int>("CustId")).ToList(); // dt is DataTable
int count =0;
foreach (var gKey in groupby)
{
count +=1;
var data = dt.AsEnumerable().AsParallel().Where(v => v.Field<int>("CustId") == gKey.Key).Select(s=>s).ToList();
for (int rowIndex = 0; rowIndex < data.Count(); rowIndex++)
{
// find the gridveiw control lable and assign the value. i hope can do easily..
if (rowIndex == 0)
{
//assign count lable value =count
}
//custID...=data[rowIndex]["CustId"].ToString();
//name...
//salary...
}
}
Abrar Ahmad Ansari
Marked as answer by Mark - MSFT on Mar 01, 2013 12:19 AM
h3ctor83
0 Points
16 Posts
Row counter on gridview group by ID
Feb 21, 2013 01:18 AM|LINK
Hi all,
Im still kinda new to aspnet. Can somehelp help to advice if this can be done? Right now i have a gridview with below sample data:
Count | custid | name | salary
---------------------------------------
1 | 11 | AA | $200
2 | 11 | BB | $300
3 | 11 | CC | $150
4 | 12 | DD | $100
5 | 12 | GG | $250
6 | 13 | EE | $250
7 | 14 | SS | $550
I need the "Count" column to display the number based on the cust ID like this:
Count | custid | name | salary
------------------------------
1 | 11 | AA | $200
| 11 | BB | $300
| 11 | CC | $150
2 | 12 | DD | $100
| 12 | GG | $250
3 | 13 | EE | $250
4 | 14 | SS | $550
If the custid is the same, the "Count" shouldnt increase but instead be displayed as empty string, just like above.
How can i achieve this?
aaa_78600
Participant
820 Points
170 Posts
Re: Row counter on gridview group by ID
Feb 21, 2013 03:17 AM|LINK
//Hello i can't write entiry code. beacuse i don't have asp.net web application. i have only vc# in my P.C. // but i can give some idea.easily you can able to do .. var groupby = dt.AsEnumerable().GroupBy(g => g.Field<int>("CustId")).ToList(); // dt is DataTable int count =0; foreach (var gKey in groupby) { count +=1; var data = dt.AsEnumerable().AsParallel().Where(v => v.Field<int>("CustId") == gKey.Key).Select(s=>s).ToList(); for (int rowIndex = 0; rowIndex < data.Count(); rowIndex++) { // find the gridveiw control lable and assign the value. i hope can do easily.. if (rowIndex == 0) { //assign count lable value =count } //custID...=data[rowIndex]["CustId"].ToString(); //name... //salary... } }