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

Displaying rich text as plain text in radgrid column

4 Answers 289 Views
Grid
This is a migrated thread and some comments may be shown as answers.
jlj30
Top achievements
Rank 2
jlj30 asked on 09 Sep 2011, 09:23 PM
Hi,

Does anyone know how to display a field containing text in RTF format as plain text in a radgrid column?
I'm currently using a GridTemplateColumn with a label in its ItemTemplate to display the text.
I've tried a simple GridBoundColumn, but without success.

Thanks for any suggestions.

Jim

4 Answers, 1 is accepted

Sort by
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 10 Sep 2011, 10:42 AM
Hello,

You remove html tag with help of below code and let me know if its not working.

using System.Text.RegularExpressions;
public static string RemoveHTML(string in_HTML)   
{  
string clearText = Regex.Replace(lv_HTML, "<(.|\n)*?>", "");
clearText = System.Web.HttpUtility.HtmlDecode(clearText)
return clearText;
}

oe try with below code.

<telerik:GridBoundColumn HtmlEncode="false"

Thanks,
Jayesh Goyani
0
jlj30
Top achievements
Rank 2
answered on 11 Sep 2011, 08:08 PM
Hi,

Thanks for the 2 suggestions, but I couldn't get either one to work for me.

What I was able to do was leverage the RadEditor which has a property simply called Text which does exactly what I want.
The label "lblBriefAnswer" is contained within an ItemTemplate of a GridTemplateColumn.

protected void lblBriefAnswer_PreRender(object sender, EventArgs e)
    {
        Label lblBriefAnswer = (Label)sender;
        lblBriefAnswer.Text = HTML2PlainText(lblBriefAnswer.Text);
    }
 
public static string HTML2PlainText(string htmlText)  
    {
        RadEditor editor = new RadEditor();
        editor.Content = htmlText;
        String plainText = editor.Text;
        return plainText;
    }

Jim
0
jlj30
Top achievements
Rank 2
answered on 12 Sep 2011, 06:25 PM
My apologies to Jayesh.  The code provided worked just fine.
It must have been a finger check on my part.
Thanks for the solution.
Jim
0
Jayesh Goyani
Top achievements
Rank 2
answered on 12 Sep 2011, 06:33 PM
Hello Jim,

its ok. my friend.

Thanks,
Jayesh Goyani
Tags
Grid
Asked by
jlj30
Top achievements
Rank 2
Answers by
Jayesh Goyani
Top achievements
Rank 2
jlj30
Top achievements
Rank 2
Share this question
or