Neo
Neo

Reputation: 16219

how can i create html tags in asp.net like ul, li, a etc

How can I create HTML tags in asp.net like ul, li, a, etc

In detail and in the simplest way possible with all HTML tags and dynamic manner.

Upvotes: 9

Views: 50032

Answers (5)

Dima Shmidt
Dima Shmidt

Reputation: 905

If I understand you correctly you can use Repeater control:

<ul>
<asp:Repeater runat="server" ID="repeater1">
    <ItemTemplate>
        <li> <%# Container.DataItem %> </li>
    </ItemTemplate>
</asp:Repeater>
</ul>

Then bind this control with your collection of your data:

repeater1.DataSource = YourCollectionOfStringHere;
repeater1.DataBind();

Hope it will be helpful. If not, sorry for this )

Upvotes: 11

rtpHarry
rtpHarry

Reputation: 13125

You can create a ul / li set using the BulletedList control:

It also has a DisplayMode which you can use to make it display hyperlinks:

Upvotes: 3

Skorpioh
Skorpioh

Reputation: 1355

Well, the simplest but not object oriented way to do it:


Add to your .aspx file:

<asp:Literal ID="myLiteral" runat="server"></asp:Literal>


Add to your .aspx.cs file:

myLiteral.Text = "<ul><li>apple</li><li>orange</li><li>kiwi</li></ul>";


Not nice, but works :)




The easiest object oriented way to do it is with the HtmlGenericControl class. You can create any tag you want with it and at least it assures that these tags are closed properly. Example to create a <div>:

string s="This is <strong>a test</strong> of the html HtmlGenericControl class";
HtmlGenericControl ge = new HtmlGenericControl("div");
ge.InnerHtml=s;
this.PlaceHolder1.Controls.Add(ge);



Just keep in mind, that both solutions are working, but neither one is the nice way to get things done. For generating <a> tags you should use HtmlAnchor control, for <div> you should use <asp:Panel> for <span> you should use <asp:Label>, for your list you should use <asp:BulletedList> or the repeater control and so on.

Hope this helps.

Upvotes: 7

Madhur Ahuja
Madhur Ahuja

Reputation: 22661

Use HtmlGenericControl. That's exactly what you are looking for:

http://msdn.microsoft.com/en-us/library/7512d0d0(v=VS.90).aspx

Upvotes: 8

user536158
user536158

Reputation:

You can create them just like normal html:

example:

<ul type="disc">
        <li>A</li>
        <li>B</li>
        <li>C</li>
        <li>D</li>
        <li>E</li> </ul>

if you want to tranform them to server side controls you can just add runat="server"

Upvotes: 1

Related Questions