Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
DataColumn SlCol = new DataColumn("#", typeof(System.Int32));
dtGetList.Columns.Add(SlCol);
SlCol.AutoIncrement = true;
SlCol.AutoIncrementSeed = 1;
Ex: Grid On FormLoad
sl.No Name
1 A
2 B
3 C
4 D
5 E
6 F

After Sorting Name Column

VB
sl.No  Name
6       f
5       e
4       d
3       c
2       b
1       a


my required o/p is

VB
sl.No  Name
1       f
2       e
3       d
4       c
5       b
6       a
Posted
Updated 1-Nov-15 21:48pm
v3

As per my understand the thread after your sorting the serial number should be in serial.

Instead of adding Serial Number column in datatable better to include in designer of datagrid by using below text <![CDATA[<%#Container.Eval(DataGrid.ItemIndex+1)%>]]> and perform action as you want. (or) Implement the serial number in OnDataGridItemDataBound event.
 
Share this answer
 
Comments
Sathish km 2-Nov-15 4:08am    
I want for WindowsForms datagrid, <![CDATA[<%#Container.Eval(DataGrid.ItemIndex+1)%>]]> is not supported.
I am not sure but we can add such logic under gridview's databound event i.e. to disabale the sorting on specific column based on condition.

Item_Bound(Object sender, DataGridItemEventArgs e)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900