Link to home
Create AccountLog in
Avatar of leekey
leekey

asked on

Gridview sorting with alphanumeric data

Hi,

I have a gridview using an objectdatasource pulling back Invoice data. The invoice numbers are:
ABC1
ABC2
ABC3
ABC10
ABC20 etc etc

I'm using the gridviews built-in sorting functionality however because the invoice number are essentially strings when sorting by invoice number ABC2 appears next to ABC20.

I know I need to essentially tell the Gridview to ignore the first 3 characters and convert into an Int.
OR is there a better way of doing this?

Any help appreciated.
Thanks Lk
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

I usually try to stick to padded numbers in an alphanumeric key:

ABC00002
ABC00020
ABC00031

This way, it can be easily sorted without having to do anything special.

Bob
Avatar of leekey
leekey

ASKER

Hi Bob,

ok - This sound like a good option. Where would I need to apply this? In the SQL or can I do something in the codebehind for the gridview?

Thanks, Lee
Lee,

How are these values generated?  Are the first three characters always the same?

Bob
Avatar of leekey

ASKER

Yes always RIL actually

Lee
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of leekey

ASKER

Thanks Bob, Worked a treat!