I'm using a WebDataGrid (2010 v1) with custom code that invokes a webservice that fetches, filters, sorts and sends back paging information. I subscribe to the "OnColumnSorted" event of the grid to fetch the newly sorted data from the webservice. I then bind the returned results to the grid but find out that the grid does another sort on top of the one I already applied in the webservice. My goals are the keep the grid wired up so that clicking a column header wil indeed invoke the "OnColumnSorted" event and will display the appropriate sort icon but I don't want the grid to actually do the sorting when I call DataBind(). How can this be accomplished?
I've tried clearing all of the sort columns prior to the call to DataBind(). This does indeed stop the sorting but removes the sort indicator on the UI. I tried adding the columns back to the sorted columns after the databind but then the grid still tries to apply it's sort even though DataBind() has already been invoked.
Hello Ed,
To access the Column SortIndicator outside of the ColumnsSorted event, you would need to use the WebDataGrid to retrieve the Columns Header using the Column Index to add the LiteralControl as shown here in the WebDataGrid PageIndexChanged Event:
protected void WebDataGrid1_PageIndexChanged(object sender, PagingEventArgs e){WebDataGrid1.Columns[0].Header.TemplateContainer.Controls.Add(new LiteralControl { ID = "sortAsc", Text = WebDataGrid1.Columns[0].Header.Text + @"<imgsrc='Images/ig_tblSortAsc.gif'/>" });}
Sincerely,Mike D.Developer Support EngineerInfragisticswww.infragistics.com/support
Mike, the sample you provided was helpful. I'm trying to extend it to show the indicator outside of the ColumnSorted event (ie Paging event). Trying to get a reference to the column header as follows, but not currently working.
grid.Columns[sortKey].Header.TemplateContainer.Controls.Clear(); grid.Columns[sortKey].Header.TemplateContainer.Controls.Add(new LiteralControl { ID = "sortAsc", Text = grid.Columns[sortKey].Header.Text + @"<img src='Images/ig_tblSortAsc.gif'/>" });
Thanks in advance for any help you can provide.
Hello Heath,Thank you for posting your inquiry to the Infragistics ASP.Net forums. The sorting of the WebDataGrid Columns will respond depending on how the SortIndicator is set. To set the SortIndicator independently when the grid is bound to a DataSource using a custom sort, an image will need to be added to the Column Header Text for the Column that was clicked.
The attached sample website demonstrates how to set the SortIndicator Ascending or Descending Image for a WebDataGrid Column using a TemplateContainer set in the Column Header with a LiteralControl. The functionality of the attached sample will work properly for a single-column sort.There are two DataSets in the sample which are used to mimic a custom sort where the displayed data is not actually sorted. Run the sample and click one of the column headers to sort the grid. When the grid refreshes after the PostBack, the grid will display the DataSet it is bound to in the data format set in code, ignoring the sort direction for the Column. This sample is for demonstration purposes.
Please take a look at the sample and let me know if this information is helpful. If you have any questions, let me know and I will be happy to assist you further.Thank you.