How to add numbering after sort?

Hi,

I have a data like this :

image

and I want it to be like this :

image

Is there anyway to add numbering after the sorting?

hey,
you can use this
datatablevariable = From x In datatablevariable.AsEnumerable() Order By convert.Tostring(x(“Branch”)),convert.ToString(x(“No”)) Select x).CopyDataTable

Thanks,
Rounak

Thanks, it works !

HI,

Is your requirement re-assign “No” column in order? If so, the following will work.

dt = dt.AsEnumerable.OrderBy(Function(r) r("Branch").ToString).Select(Function(r,i) dt.Clone.LoadDataRow({(i+1).ToString,r("Name").ToString,r("Branch").ToString},False)).CopyToDataTable

Regards,

2 Likes

This one works too. Thanks

I do not think this is you expected. You need to re arrange the No 1…n after sort by branch.

This is correct

Well I did modify it a little bit matching with my current code and it works :slight_smile: so basically I tried to learn the logic. But both from Mr. Yoichi and Mr. Rounak are both solutions :slight_smile: Thanks for discussing btw

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.