Datagrid sorting / Dataview sorting
-
Hi, Datagrid.Sort() doesnt seem to sort integers right. My code is something like this, this is a part of datagrid event: dgProductList.DataSource = catalogXml; dgProductList.CurrentPageIndex = e.NewPageIndex; //create a new dataview with xml data DataView dvCatalog = new DataView(catalogXml.Tables[0]); //provide sort expression from datagrid event dvCatalog.Sort = e.SortExpression; //assign data source dgProductList.DataSource = dvCatalog; //bind data dgProductList.DataBind(); The code works just fine for sorting any column but for integer column. When I click on a integer column to sort the result i get is: 23 234 2345 246 25 256 what i expect is obviously: 23 25 234 246 256 2345 Does anyone have any input on this? Appreciate your response. Thanks, Sucharita.
-
Hi, Datagrid.Sort() doesnt seem to sort integers right. My code is something like this, this is a part of datagrid event: dgProductList.DataSource = catalogXml; dgProductList.CurrentPageIndex = e.NewPageIndex; //create a new dataview with xml data DataView dvCatalog = new DataView(catalogXml.Tables[0]); //provide sort expression from datagrid event dvCatalog.Sort = e.SortExpression; //assign data source dgProductList.DataSource = dvCatalog; //bind data dgProductList.DataBind(); The code works just fine for sorting any column but for integer column. When I click on a integer column to sort the result i get is: 23 234 2345 246 25 256 what i expect is obviously: 23 25 234 246 256 2345 Does anyone have any input on this? Appreciate your response. Thanks, Sucharita.
The problem is it thinks that the integer column is a text column. could you give an example of how catalogXml.table[0] is populated ??
-
The problem is it thinks that the integer column is a text column. could you give an example of how catalogXml.table[0] is populated ??
-
Thanks for your response. I do a databind and bind the dataview to the datagrid. DataView.Sort() with a sort expression doesn't seem to work right. Is there a value i should be passing for sort expression to indicate the integer column?
no the sort is working fine but the problem is that it is sorting on string and not integer values. You can try changing the data type of the dataColumn something like - myTable.Columns[columnName].DataType = System.Type.GetType("int32"); This might throw an error (but its worth a try) something like - cannot change the type of a column that has already been filled with data.
-
no the sort is working fine but the problem is that it is sorting on string and not integer values. You can try changing the data type of the dataColumn something like - myTable.Columns[columnName].DataType = System.Type.GetType("int32"); This might throw an error (but its worth a try) something like - cannot change the type of a column that has already been filled with data.
catalogXml.Tables[0].Columns["Price"].DataType = System.Type.GetType("int32"); catalogXml.ReadXml( path ); if( !catalogXml.HasErrors ) { DataView dvCatalog = new DataView(catalogXml.Tables[0]); lblSortExpression.Text = e.SortExpression; dvCatalog.Sort = e.SortExpression; dgProductList.DataSource = dvCatalog; dgProductList.DataBind(); } I can't change the data type after there is data in it and cannot access myTable before loading the data! this somehow does not seem to work :(
-
catalogXml.Tables[0].Columns["Price"].DataType = System.Type.GetType("int32"); catalogXml.ReadXml( path ); if( !catalogXml.HasErrors ) { DataView dvCatalog = new DataView(catalogXml.Tables[0]); lblSortExpression.Text = e.SortExpression; dvCatalog.Sort = e.SortExpression; dgProductList.DataSource = dvCatalog; dgProductList.DataBind(); } I can't change the data type after there is data in it and cannot access myTable before loading the data! this somehow does not seem to work :(
have a look at the following link - http://www.dotnet247.com/247reference/msgs/56/283683.aspx Same problem as yours.
-
have a look at the following link - http://www.dotnet247.com/247reference/msgs/56/283683.aspx Same problem as yours.