Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

asp.net

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.

like image 521
Neo Avatar asked Dec 15 '10 08:12

Neo


People also ask

What is HTML Li and UL tag?

The <li> tag defines a list item. The <li> tag is used inside ordered lists(<ol>), unordered lists (<ul>), and in menu lists (<menu>). In <ul> and <menu>, the list items will usually be displayed with bullet points. In <ol>, the list items will usually be displayed with numbers or letters. Tip: Use CSS to style lists.

Can Li tag be used without UL?

If it gets displayed correctly, it's only a matter of luck. As you seem to define dangerous by "break in browsers for the end user's ability to view the page as intended", then yes it's dangerous.

What is the use of Li tag in HTML?

The <li> HTML element is used to represent an item in a list. It must be contained in a parent element: an ordered list ( <ol> ), an unordered list ( <ul> ), or a menu ( <menu> ). In menus and unordered lists, list items are usually displayed using bullet points.

What is ASP tag in HTML?

ASP stands for Active Server Pages. ASP is a development framework for building web pages. ASP supports many different development models: Classic ASP. ASP.NET Web Forms.


4 Answers

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 )

like image 81
Dima Shmidt Avatar answered Oct 25 '22 20:10

Dima Shmidt


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

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

like image 41
Madhur Ahuja Avatar answered Oct 25 '22 21:10

Madhur Ahuja


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.

like image 32
Skorpioh Avatar answered Oct 25 '22 22:10

Skorpioh


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

  • http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.bulletedlist.aspx

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

  • http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.bulletedlist.displaymode.aspx
like image 40
rtpHarry Avatar answered Oct 25 '22 21:10

rtpHarry