【问题标题】:Display DB HTML text without tags using asp.net [duplicate]使用asp.net显示没有标签的DB HTML文本[重复]
【发布时间】:2019-05-13 10:13:42
【问题描述】:

我有一些从 SQL 数据库中检索到的带有 HTML 标记的文本。如何使用 asp.net 在浏览器中显示没有 HTML 标记的相同文本?

【问题讨论】:

    标签: html sql asp.net


    【解决方案1】:

    您可以使用@Html.Raw(Model.text)打印html

    【讨论】:

      【解决方案2】:

      我用form-view绑定数据库得到结果。

      如果您存储了一些带有 HTML 标记的消息以在浏览器中查看,请使用:

      project.aspx 页面

      '<asp:FormView ID="fvhtml" runat="server" Width="100%">
          <ItemTemplate>
              <asp:Label ID="lblmsg" runat="server" Text="Message" Font-Size="25px"></asp:Label>
              <asp:Label ID="lblhtml" runat="server" Text='<%# Bind("**`column name`**") %>' />
              <br />
          </ItemTemplate>
      </asp:FormView>'
      

      project.aspx.cs

      SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connectionstring name"].ToString());
      
      //message binding start from here
      try
      {
          con.Open();
          SqlDataAdapter sqlda = new SqlDataAdapter("SELECT TOP 1 column name FROM table name", con);
          DataTable dt = new DataTable();
          sqlda.Fill(dt);
          fvhtml.DataSource = dt;
          fvhtml.DataBind();
      }
      catch (Exception ex)
      {
          ex.Message.ToString();
      }
      finally
      {
          con.Close();
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-10-12
        • 2023-03-13
        • 1970-01-01
        • 1970-01-01
        • 2018-09-11
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多