Click here to Skip to main content
14,773,207 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
I have some text stored in a database and i want to display it as html paragraph, is there a way to do it using

here is what i did to add text to database:

protected void btnSubmit_Click(object sender, EventArgs e)
        if (txtAbout.Text.Length != 0)

            string AboutText = txtAbout.Text;
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

            SqlCommand cmd1 = new SqlCommand("INSERT into AboutUsData Values ('" + AboutText + "')", con);

as to retrieve it is the question:

protected void Page_Load(object sender, EventArgs e)
       SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

       SqlCommand com = new SqlCommand("SELECT * from AboutUsData", con);
       SqlDataAdapter da = new SqlDataAdapter(com);
       DataSet ds = new DataSet();
       da.Fill(ds, "AboutUsData");

      TextBox1.Text = ds.Tables["AboutUsData"].Rows[0]["About"].ToString();


i want it to be as a paragraph instead of textbox.
Updated 29-Jul-14 4:20am
Leo Chapiro 29-Jul-14 9:13am
What have you already achieved? Show your code please.
AlaaHalabi 29-Jul-14 9:21am
i have updated the question with code :)

refer this.. :)

RichTextBox Overview[^]
You can try something like this :

string strAbout = ds.Tables["AboutUsData"].Rows[0]["About"].ToString();
strAbout = "<p>" + strAbout + </p>
//Take a label
lblAbout.Text = Server.HtmlDecode(strAbout );

Best of Luck :)
Raje_ 29-Jul-14 9:32am
shibusen 29-Jul-14 9:37am
Thanks Raje
AlaaHalabi 29-Jul-14 9:51am
You are a hero! Thanks a lot! :)
shibusen 29-Jul-14 9:54am
Thanks AlaaHalabi
Add this to your HTML where you want the paragraph to appear:
<p id="paragraph" runat="server"></p>

Populate the paragraph from the page_load with:
this.paragraph.InnerText = "This is a test of dynamicly adding paragraph text";
AlaaHalabi 29-Jul-14 9:56am
Excellent! This is exactly what im looking for! Thank you for your help. :)
Just create a paragraph tag and make it as runat="server", and call it in your codebehind page. you can treat that paragraph tag as a server control now.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900