Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can't sort data int properly with gridview

I want to sort my integer data, but I want to make it easier to read, if I have data like 1000000000 I want it display 1,000,000,000 so I use this query in mysql;

format(col_name,0)

I tried to sort it with sort function in C# using gridview, I use this to sort gridview;

protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
    tempExp = e.SortExpression;
    Session["sort"] = tempExp;
    showData();
}
void showData()
{
    tempExp = (string)Session["sort"];
    sortProperty = SortDirection.Descending;
    sortedView = new DataView(dataset); 
    sortedView.Sort = tempExp + " Desc"; 
    GridView1.DataSource = sortedView; 
    GridView1.DataBind();
}

but this is what happen when I tried to sort data2;

+================+=================+
|     data1      |      data2      |
+================+=================+
|     21,039,000 |               6 |
|     30,080,000 |           4,062 |
|    209,120,040 |          28,692 |
|    201,200,900 |           2,115 |
|      1,100,900 |          15,858 |
+================+=================+

how can I fix it?

like image 267
Darjeeling Avatar asked Feb 28 '26 03:02

Darjeeling


1 Answers

First solution:

Do the formatting in C# code.

int num = 11111111;
string s = num.ToString("N0");

Second solution:

Include the original int columns in the sql query along with the formatted value & apply the sort on original int columns & bind the formatted columns in gridview for display.

like image 124
Kapil Khandelwal Avatar answered Mar 01 '26 21:03

Kapil Khandelwal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!