Insert value of TinyMCE editor to Database and display in ASP.Net GridView

Last Reply 8 months ago By pandeyism

Posted 8 months ago

How to design free text area with B, I...

I insert  Tiny MCE Rich Text Editor value to sql server in ASP.Net Web application.

After i try to retrieving and bind to a gridview, but it displaying with html tags (<p>...).

How to remove that tags while retrieving.

You are viewing reply posted by: pandeyism 8 months ago.
Posted 8 months ago

Hi eswardatta,

Please refer below article.

Save (Insert) and Retrieve (Display) TinyMCE contents from database in ASP.Net

HTML

<script type="text/javascript" src="//tinymce.cachefly.net/4.0/tinymce.min.js"></script>
<script type="text/javascript">
    tinymce.init({
        selector: 'textarea',
        width: 500,
        height: 300,
        resize: false
    });        
</script>
<div class="ScrollBar">
    <textarea name="txtHTMLContent" class="ScrollBar" rows="2" cols="20" id="txtHTMLContent"
        runat="server"></textarea>
    <br />
    <br />
</div>
<asp:GridView ID="gvHtml" runat="server" AutoGenerateColumns="false">
    <Columns>
        <asp:BoundField DataField="Content" HeaderText="Content" HtmlEncode="false" />
    </Columns>
</asp:GridView>

Namespaces

C#

using System.Configuration;
using System.Data.SqlClient;

Code

C#

protected void Page_Load(object sender, EventArgs e)
{
    if (!this.IsPostBack)
    {
        string query = "SELECT [Content] FROM [HTMLContent]";
        string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
        using (SqlConnection con = new SqlConnection(conString))
        {
            using (SqlCommand cmd = new SqlCommand(query, con))
            {
                con.Open();
                using (SqlDataReader sdr = cmd.ExecuteReader())
                {
                    if (sdr.Read())
                    {
                        txtHTMLContent.InnerHtml = sdr["Content"].ToString();
                    }
                    gvHtml.DataSource = sdr;
                    gvHtml.DataBind();
                    sdr.Close();
                }
                con.Close();
            }
        }
    }

}

Screenshot