Kajah User
Kajah User

Reputation: 591

DataView sorting alphabetically

I am getting two inputs from the user. One is modalno and other is description and one add button if the user clicks the add button i goes and it should go and insert in the correct sorting order so far i have used this code in loadgrid()

DataView dv = ModelDataset.Tables[0].DefaultView;
dv.Sort = "MODEL_NO";
grvModelNo.DataSource = dv;
grvModelNo.DataBind();

It is sorting correctly but my issue is :

modalno    description
1          test
45         test
455        test
50         test

'455' should insert after '50' it is inserting before '50' it is checking first digit only i think.

Note: Here Modal_No is varchar()

Upvotes: 1

Views: 754

Answers (1)

cjk
cjk

Reputation: 46425

It is sorting as text, not as a number. If you want it to sort it as a number, you must present it as a number - cast it.

Why is it a varchar anyway, as it looks a lot like it will only be storing numbers...

Upvotes: 3

Related Questions