I have an error panel that is subbed in to a page if an error goes wrong to gracefully handle and display errors. Currently, I am just appending the error messages to a string and pushing that to a label. If you have multiple errors, this gets messy. Therefore, I'd like to push each error to a list item in a bulleted, unordered list.
How can I dynamically generate, from a vb codebehind file, new list items inside of an undordered list element?
Why not use a BulletedList
control? This control will render an unordered list to the client.
<asp:BulletedList ID="BulletedList" runat="Server" BulletStyle="NotSet">
</asp:BulletedList>
You can then add list items programmatically from code behind like this.
BulletedList.Items.Add("Item1");
You can also accomplish this by adding runat='server'
to reference the UL
tag server side.
<ul id="uList" runat="server">
</ul>
Then in the code behind use the InnerHtml
property to programmatically add LI
tags to the contents within the opening and closing UL
tags.
uList.InnerHtml += "<li>Item1</li>";
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