Displaying rich text as plain text in radgrid column

5 posts, 1 answers
  1. jlj30
    jlj30 avatar
    102 posts
    Member since:
    Jan 2011

    Posted 09 Sep 2011 Link to this post

    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
  2. Answer
    Jayesh Goyani
    Jayesh Goyani avatar
    2733 posts
    Member since:
    May 2010

    Posted 10 Sep 2011 Link to this post

    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
  3. jlj30
    jlj30 avatar
    102 posts
    Member since:
    Jan 2011

    Posted 11 Sep 2011 Link to this post

    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
  4. jlj30
    jlj30 avatar
    102 posts
    Member since:
    Jan 2011

    Posted 12 Sep 2011 Link to this post

    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
  5. Jayesh Goyani
    Jayesh Goyani avatar
    2733 posts
    Member since:
    May 2010

    Posted 12 Sep 2011 Link to this post

    Hello Jim,

    its ok. my friend.

    Thanks,
    Jayesh Goyani
Back to Top