Hello Support,
I am having trouble with custom sorting accessing values that were set using cellformatting(). I have a Gridview that is databound to a custom class, AutoGenerateColumns = false, adding columns using grid.MasterTemplate.Columns.Add(), using CellFormatting() to populate the data on some of the columns that are not in the custom class.
Values that are assigned from the databound class show up ok, but the Values that were assigned using CellFormatting() are always null.
How can I access the values set using CellFormatting() { e.CellElement.Text = "X"} ?
Thanks
void grid_CustomSorting(object sender, GridViewCustomSortingEventArgs e) { foreach (var descriptor in e.Template.SortDescriptors) { if (uicomponents != null && !String.IsNullOrEmpty(descriptor.PropertyName) ) { var customcolumn = uicomponents.FirstOrDefault( ui => ui.FriendlyName.Equals(descriptor.PropertyName)); if (customcolumn != null) { int result = 0; System.Diagnostics.Debug.WriteLine(descriptor.PropertyName); try { //var cellValue1 = (string)e.Row1.Cells[descriptor.PropertyName].Value; //var cellValue2 = (string)e.Row2.Cells[descriptor.PropertyName].Value; var cellValue1 = (string)e.Row1.Cells[descriptor.PropertyIndex].Value; var cellValue2 = (string)e.Row2.Cells[descriptor.PropertyIndex].Value; if (cellValue1 == cellValue2) { result = 0; } else if (cellValue1 != null) { result = 1; } else if (cellValue2 != null) { result = -1; } } catch { } e.SortResult = result; e.Handled = true; return; } else { //Check here if the value for cells that are databound are populated. var cellValue1 = (string)e.Row1.Cells[descriptor.PropertyIndex].Value; var cellValue2 = (string)e.Row2.Cells[descriptor.PropertyIndex].Value; //This actually works. System.Diagnostics.Debug.WriteLine(cellValue1 + " " + cellValue2); } } } e.Handled = false; }