Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to sort numerically, instead of by string, on a Telerik RadGrid ASP.NET Ajax?
    primarykey
    data
    text
    <p>I have a RadGrid that has a column, <em>Loss Amount</em>, 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. How can I do it?</p> <p>My code is listed below. 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?</p> <h2>Column:</h2> <pre><code>&lt;rad:GridNumericColumn DataField="Loss Amount" UniqueName="Loss Amount" HeaderText="Loss Amount" SortExpression="Loss Amount" \&gt; &lt;HeaderStyle Width="140"&gt; &lt;ItemStyle Width="140" HorizontalAlign="Right"ForeColor="Maroon" /&gt; &lt;/rad:GridNumericColumn&gt;` </code></pre> <h2>NeedDataSource Event:</h2> <pre><code>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(); } </code></pre> <h2>ItemDataBound Event:</h2> <pre><code>protected void grdCustomerAssignments_ItemDataBound(object sender, GridItemEventArgs e) { FormatCurrency(item["Loss Amount"].Text); } protected string FormatCurrency(string text) { if (text.Length &gt; 3) { string result = String.Empty; char[] tmpArray = text.ToCharArray(); Array.Reverse(tmpArray); string tmpString = new String(tmpArray); while (tmpString.Length &gt; 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); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload