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.
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.
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.
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.
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.
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 )
Use HtmlGenericControl. That's exactly what you are looking for:
http://msdn.microsoft.com/en-us/library/7512d0d0(v=VS.90).aspx
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.
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With