Ask a Question related to ASP.NET Data Grid Control, Design and Development.
-
Todd #1
How to sort a String column as Numeric?
I have a datagrid (dgResults) that I am populating from a SQL stored
procedure. After I fill my dataset (ds), I cache the dataset this
way: Session("ds") = ds.Tables("Table1").Defaultview. After this I
set the Grid's datasource to the dataset and bind the Grid.
My sort is working fine for all but 2 columns. The 2 giving me
trouble are formatted as Currency. It's sorting these as if they are
strings ($1, $11, $2, $22, etc). How can I get these to sort in the
proper order (numeric)? I don't know if I need to change anything in
the sort command procedure, but here it is below:
Private Sub dgResults_SortCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridSortCommandEvent Args) Handles
dgResults.SortCommand
Dim dv2 As New DataView
dv2 = Session("ds")
dv2.Sort = e.SortExpression
dgResults.DataSource = dv2
dgResults.DataBind()
End Sub
Todd Guest
-
numeric part of a string
Can anyone tell me how can I get the numeric part of a string . for example I'm using this..Select substring('walnut 2224... -
string becomes numeric?
Hi, I am trying to dump a query out into an excel. I found that a varchar datatype column will be converted to numeric in the Excel. For... -
Ado sort error-Ado Sort -Relate, Compute By, or Sort operations cannot be done on column(s) whose key length is unknown or exceeds 10 KB.
Ado Sort -Relate, Compute By, or Sort operations cannot be done on column(s) whose key length is unknown or exceeds 10 KB. hi, guys i have asp... -
Descending numeric sort using Guttman-Rosler Transform
The following program is a simple example of sorting positive integers using the Guttman-Rosler transform: print map { substr($_, 4) } sort map {... -
Problem converting array string back to numeric
I'm afraid I don't know enough about your situation to help. How are you sending your values to ASP? It sounds to me like this is more like an ASP... -
Todd #2
Re: How to sort a String column as Numeric?
in the sort_command sub I thought that converting all the string typed
numbers back to decimals, then sorting them, then re-binding them to
the DataGrid would work. But it still results in the numbers being
sorted as strings:
997.48
974.63
9389.42
927.43
The code I used in the sort_command sub is below:
Dim y As Integer
Dim x As Integer = 0
Dim dv3 As New DataView
dv3 = Session("ds") 'the dataset is cached
y = dv3.Count
While x < y
'convert each item in the Dataview back to type Decimal
dv3.Item(x).Row.Item("CustBenefit") =
CDec(dv3.Item(x).Row.Item("CustBenefit"))
x += 1
End While
'sort all the decimals
dv3.Sort = e.SortExpression
'set the datasource and re-bind it
dgResults.DataSource = dv3
dgResults.DataBind()
Can anyone please help with this issue? It is very annoying that I
have not been able to find a resource to help answer such a silly
problem. I'm only trying to sort dollar amounts, not discover the
meaning of life! Thanks.
Todd Guest



Reply With Quote

