This is a migrated thread and some comments may be shown as answers.

Sorting problem with string fields containing rich text

3 Answers 89 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Boris
Top achievements
Rank 1
Boris asked on 22 Jan 2013, 02:51 PM
I may have a sort problem on one of my fields in a RadGrid.

I have a description field that is set in a RadEditor.  It's rich text and unlimited length.  (varchar(max)).

In the grid itself, when the field is displayed, I have a call in the ItemDataBound event handler to strip the field of HTML and only display the first 40 characters.  The code for the stripping is as follows:

 string clearText = Regex.Replace(incoming_string, "<(.|\n)*?>", "");
  clearText = System.Web.HttpUtility.HtmlDecode(clearText);


Even with that the sort on that field does not appear to work perfectly.  There are still a few records with stray characters.  This may or may not be a problem in real life as these records are casually entered test data.  Still I'd like to know if I'm doing anything basically wrong.

Suggestions?

3 Answers, 1 is accepted

Sort by
0
Angel Petrov
Telerik team
answered on 25 Jan 2013, 12:32 PM
Hello Boris,

RadGrid is a bound control and does operations like filtering and sorting on a database level. When you change data do the changes apply in the data source of the grid? I suggest that you first make the changes in the field and after this is done bind the database to the grid. Thus you should be able to sort correctly. Additionally it would be best if you can show us an example of this so we could give you a more precise answer.

Kind regards,
Angel Petrov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Boris
Top achievements
Rank 1
answered on 25 Jan 2013, 01:09 PM
When you change data do the changes apply in the data source of the grid?

Actually no.  The idea is not to change the data source.  (Or does doing it in the ItemDataBound event count?) It's just that displaying the data as is (big fonts, colors) would be disruptive to the operation of the grid as a whole.  And generally the contents of that field would be too big to display in their entirety anyway.  I have no choice but to take a sample.


0
Accepted
Angel Petrov
Telerik team
answered on 30 Jan 2013, 09:50 AM
Hello Boris,

When changes are made in the OnItemDataBound event you only change the visible text and you are not touching the DataSource of the grid. In order to sort correctly changes must be made in the DataSource. If this is not applicable in your case you can implement some kind of middle layer that you can bind to the grid.

Regards,
Angel Petrov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Boris
Top achievements
Rank 1
Answers by
Angel Petrov
Telerik team
Boris
Top achievements
Rank 1
Share this question
or