Click here to Skip to main content
15,905,963 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HTML
<h3>
<a href="#"> text</a>
<h3></h3></h3>

C#
 HtmlGenericControl header = new HtmlGenericControl("h3");
 HtmlGenericControl anchor = new HtmlGenericControl("a");
 anchor.Attributes.Add("href", "#");
 anchor.Attributes.Add("InnerText", "'" + k["Question"].ToString() + "'");// i am getting some value from sharepoint custom list which is text here//
                
header.Controls.Add(anchor);

can someone help me.
Posted
Updated 21-Nov-11 0:34am
v3
Comments
hzawary 21-Nov-11 8:19am    
Is platform ASP.NET?

I guess you are doing this in Asp.Net. You may try it as below.

1) Declare Div in your Aspx.
ASP.NET
<div id="dvMyHtml" runat="server"></div>


2) In code-behind
C#
StringBuilder sbHtml = new StringBuilder();

sbHtml.Append("<h3>");
sbHtml.Append("<a href="\"#\"">");
sbHtml.Append(Convert.ToString(k["Question"]));
sbHtml.Append("</a>");
sbHtml.Append("<h3></h3></h3>");

dvMyHtml.InnerHtml = sbHtml.ToString();
 
Share this answer
 
In PHP it is simple and we have:
PHP
echo '<h3><a href="#"> text</a><h3></h3></h3>';

but in asp.net C# code behind we can use similar way
C#
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write("<h3><a href="#"> text</a><h3></h3></h3>");
    }
}
 
Share this answer
 
v2
The simplest way to output HTML is to do it directly as in the other two answers. But if you're going to use controls, InnerText is not an attribute, you need to use anchor.InnerHtml = "'" + k["Question"].ToString() + "'".
 
Share this answer
 

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