ASP.NET List-Item Problem...

liunx

Guest
I'm pulling data from an XML file into an ASP.NET web form, and it's working fine. But I have a question concerning how ASP.NET works with list-items using DataLists. This is how my page is setup:
<!-- m --><a class="postlink" href="http://www.douglas-county.com/docs/txt/aspxcode.txt">http://www.douglas-county.com/docs/txt/aspxcode.txt</a><!-- m -->

It works fine, but this is the code that's outputed for the list-item:
<!-- m --><a class="postlink" href="http://www.douglas-county.com/docs/txt/browsercode1.txt">http://www.douglas-county.com/docs/txt/browsercode1.txt</a><!-- m -->

As you can see, the unordered list-item is not well-formed. If I try to move the <ul> tags inside of the DataList, I receive this error message:
Server Error in '/' Application.
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: Type 'System.Web.UI.WebControls.DataList' does not have a property named 'ul'.

Source Error:
Line 57:
Line 58: <asp:DataList id="aspxAL2" runat="server" cellpadding="1" cellspacing="1" width="100%">
Line 59: <ul>
Line 60: <ItemTemplate>
Line 61: <li>

...and if I move them inside of the DataList container itself, this is the resulting code:
<!-- m --><a class="postlink" href="http://www.douglas-county.com/docs/txt/browsercode2.txt">http://www.douglas-county.com/docs/txt/browsercode2.txt</a><!-- m -->

So my question is:
Does anyone know of a way to use list-items within an ASP.NET page so that the resulting code is well-formed in the browser? Like this:
<td>
<ul>
<li>List Item 1</li>
<li>List Item 2</li>
<li>List Item 3</li>...
</ul>
</td>

I hope to hear some great advice. Thanks in advance.create a label that runs at the server, then create a loop that adds the code in it. Like:

thisIsALabel.Text="\n<ul>";
for(int i=0; i<numbOfItems;i++)
{
thisIsALabel.Text+="\n\t<li>"+itemArray+"</li>";
}
thisIsALabel.Text+="\n</ul>";
well, atleast that is the cleanest way to do it (if you'r looking at the source code)

hope that helps!
JoelI see that this answer is in JScript, and I'm working on using VB.NET instead. Is there a way to do this in VB.NET, or will I have no choice?

Also, isn't it kind of strange that the built-in ASP.NET methods don't form proper code? Why even use DataGrids, DataLists or Repeaters if the resulting code is not going to be well-formed? This seems kind of hokey...It's actually C# code behind. Sorry, i don't know enough VB to translate it over, but it will be very simmilar, and it will work. The logic is creating a label WebForm and setting it's text to the HTML code that you want. It is really hokey, but it's the only way to have absolute control over your HTML code. It's kinda like PHP if you've ever done used it. But yeah, it's C# code behind.

Joel

p.s. all the webcontrols are just fancy ways of dynamically generating HTML code, so if you don't like how it works. . . create your own :)!
 
Back
Top