Hi,
I found a solution to sorting a WinGrid using SortComparer, however I cannot find a solution for a WebGrid. I am trying to sort a grid so it will sort like it does in excel. Currently it is sorting values as 1%, 11% 2% etc rather than 1%, 2%, 11%. The reason why I cannot simply make it a integer field is because there are columns with text in them such as - or N/A.
Does anyone have a solution?
Thanks in advance.
Dan
I was thinking these emails will help me resolve my issue but seems like they are not working. Can you please direct me to the right links.
AllowSorting should be set to Yes (on server) as opposed to OnClient.
Alex,
I got the same problem. Could you specify how to postback and where to postback in this case?
Thanks
Hi Alex,
Thank you for getting back to me. I looked at the post you sent me and rather than creating my own sorting algorithm I decided to return another column when databinding and sorting by that field.
protected void UltraWebGrid1_SortColumn(object sender, Infragistics.WebUI.UltraWebGrid.SortColumnEventArgs e){
//Save(); e.Cancel = true; Session["Sort"] = "True"; Session["SortColumn"] = e.ColumnNo - 1;}Then to get it to sort I did the following in the Page_PreRender method:
UltraWebGrid.Bands[0].SortedColumns.Add(UltraWebGrid.DisplayLayout.Bands[0].Columns[Convert.ToInt32(Session["SortColumn"])]);
for (int y = 0; y < UltraWebGrid.Bands[0].SortedColumns.Count; y++) { if (UltraWebGrid.Bands[0].SortedColumns[y].Key != UltraWebGrid.DisplayLayout.Bands[0].Columns[Convert.ToInt32(Session["SortColumn"])].Key) UltraWebGrid.Bands[0].SortedColumns.RemoveAt(y); } UltraWebGrid.DataSource = dv; UltraWebGrid.DataBind(); } } break; default: break; }}
This seems to work alright. The problem I am having now is if I uncomment the Save() method call in UltraWebGrid1_SortColumn then I get a null reference error. The stack trace is below:
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.] Infragistics.WebUI.UltraWebGrid.UltraWebGrid.UpdateDBRow(UltraGridRow row, UltraGridRow oldRow) +155 Infragistics.WebUI.UltraWebGrid.UltraWebGrid.ProcessChanges(StateChanges stateChanges, Boolean fireEvents) +1557 Infragistics.WebUI.UltraWebGrid.UltraWebGrid.RaisePostDataChangedEvent() +161 System.Web.UI.Page.RaiseChangedEvents() +165 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1485
Please at your earliest convience can you help me troubleshoot this? Is this a bug in the UltraWebGrid?
Thanks in advance,