从数据库中检索文本并将其显示为HTML段落

从数据库中检索文本并将其显示为HTML段落

本文介绍了从数据库中检索文本并将其显示为HTML段落的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些文本存储在数据库中,我希望将其显示为html段落,有没有办法使用asp.net?



这里是我为数据库添加文本所做的:



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:

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:

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想要它作为段落而不是文本框。



i want it to be as a paragraph instead of textbox.

推荐答案


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





最好运气:)



Best of Luck :)


<p id="paragraph" runat="server"></p>



从page_load填充段落:


Populate the paragraph from the page_load with:

this.paragraph.InnerText = "This is a test of dynamicly adding paragraph text";


这篇关于从数据库中检索文本并将其显示为HTML段落的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 21:40