how can I fill an unordered list with values from SQL Server 2008 R2 SP1? xD I have this, using a asp:repeater:
<ul style="list-style:none">
<asp:Repeater ID="deptList" runat="server">
<ItemTemplate>
<li>
<asp:HyperLink runat="server"
Text='<%# Eval("Name") %>'
NavigateUrl='<%# Link.ToDepartment(Eval("DepartmentID").ToString()) %>'
/>
</li>
</ItemTemplate>
</asp:Repeater>
</ul>
and the output HTML:
<ul style="list-style:none">
<li>
<a href="http://...">value1</a>
</li>
<li>
<a href="http://...">value2</a>
</li>
<li>
<a href="http://...">value3</a>
</li>
</ul>
Is there a better way to do this?
You can use a for loop to iterate all the values from the data source. A sample:
<ul>
<% foreach(var item in Collection) { %>
<li><%=item.Property%></li>
<% } %>
</ul>
And also you can use other data controls provided by ASP.NET, such as DataGrid.
And, if you insist using Repeater, I suggest you put <ul>
in HeaderTemplate
, </ul>
into FooterTemplate
, this prevents empty <ul></ul>
.
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