Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I have 7 columns in asp.net datagrid and I am able to sort them by using SortExpression attribute in design page and it is working fine.

One of the column which store User ID in DB but while displaying on grid it is get converted to User Name. So while sorting this column after clicking on header sorted result (User Name) is not in order because actual sorting happen on User ID which is stored in db.

Grid which populate data is coming from Database 'A' and actual User information stored in DB 'B'. As per company security policy I cannot use Cross DB query to convert User ID->User Name while reading it from SP.

Can anyone please help me how to achieve sorting from Code behind in above situation.

What I have tried:

i have tried above scenario on my machine and facing issue as mentioned in above description.
Posted
Updated 19-May-16 12:58pm

1 solution

Assuming you are using Template fields in your datagrid then check what the SortExpression is set to for the User Name column - if it is set to the User Id then set it to the name of the column you want to sort by.
Alternatively you can create an event handler for the OnSorting event of a GridView and sort the data in your code behind page - MSDN link below.
GridView.Sorting Event at MSDN[^]

Kind Regards
 
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