Click here to Skip to main content
15,880,299 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 asp.net?

here is what i did to add text to database:

C#
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);

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





as to retrieve it is the question:

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


       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();
       con.Close();


   }


i want it to be as a paragraph instead of textbox.
Posted
Updated 29-Jul-14 3:20am
v2
Comments
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[^]
 
Share this answer
 
You can try something like this :

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


Best of Luck :)
 
Share this answer
 
v2
Comments
Raje_ 29-Jul-14 9:32am    
+5
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:
C#
this.paragraph.InnerText = "This is a test of dynamicly adding paragraph text";
 
Share this answer
 
Comments
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.
Cheers
 
Share this answer
 
v2

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