使用asp.net显示不带标记的DB HTML文本



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

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

我使用表单视图绑定数据库以获得结果。

如果您存储了一些带有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();
}

最新更新