I have some text with HTML tags retrieved from an SQL database. How could I display the same text without the HTML tags in the browser using asp.net ?
2 Answers
I got it using form-view to bind the database to get the result.
If you stored some message with HTML tags to view in browser use this:
project.aspx page
'<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();
}