views:

395

answers:

1

I have a RadGrid that has a Loss Amount column which I would like to be able to sort. Currently it does sort, but only by string value. I have the column type as GridNumericColumn. Can someone point me in the right direction please? Thanks in advance.

Update:

Ok, here's my code. I am also formatting the column text to show the currency. One thing I did notice is that I am returning a string value from the Format method. Could this be the reason?

Column:

<rad:GridNumericColumn DataField="Loss Amount" UniqueName="Loss Amount" HeaderText="Loss Amount" SortExpression="Loss Amount" \>
<HeaderStyle Width="140">
<ItemStyle Width="140" HorizontalAlign="Right"ForeColor="Maroon" /> </rad:GridNumericColumn>

NeedDataSource Event:

protected void grdCustomerAssignments_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
GetAssignments();
grdCustomerAssignments.DataSource = Assignments;
}

private void GetAssignments()
{
if (Assignments == null)
Assignments = new DataTable();

SPList list = SPContext.Current.Web.Lists["Listings"];
SPView view = GetCustomerView();
SPListItemCollection items = list.GetItems(view);

Assignments = items.GetDataTable();

foreach (DataColumn column in Assignments.Columns)
{
    column.ColumnName = XmlConvert.DecodeName(column.ColumnName);
}

Assignments.AcceptChanges();

}

ItemDataBound Event:

protected void grdCustomerAssignments_ItemDataBound(object sender, GridItemEventArgs e)
{
FormatCurrency(item["Loss Amount"].Text);
}

protected string FormatCurrency(string text)
{
if (text.Length > 3)
{
string result = String.Empty;
char[] tmpArray = text.ToCharArray();
Array.Reverse(tmpArray);
string tmpString = new String(tmpArray);

    while (tmpString.Length > 3)  
    {  
        string threeChars = tmpString.Substring(0, 3);  
        result = String.Concat(result, threeChars, ",");  
        tmpString = tmpString.Remove(0, 3);  
    }  

    result = String.Concat(result, tmpString);  
    tmpArray = result.ToCharArray();  
    Array.Reverse(tmpArray);  
    text = new String(tmpArray);  
}  

return String.Concat("$ ", text);  

}

A: 

Also check that the source field is of numeric data type and it is not string. You can test that easily enabling editing - if you edit an item an exception will be thrown if string value is attempted to be assigned to the Telerik numeric editor.

Dick

Dick Lampard
Tried the edit, no exception was thrown. Although there is still a comma in the value. Wouldn't that make it a string value?
jhorton