The reason this is occuring is that within your <ItemTemplate> you are creating a new <ol> element for each of the Items in your collection and adding a single <li> element within that Ordered List.
This explains the reason that you are receiving a "1." for each of your elements. You could try wrapping the DataList within an <ol> element :
cms9651
Member
175 Points
573 Posts
[C# net 2] Datalist numbered list
Jan 29, 2013 04:58 PM|LINK
hello, hope in your help.
this is my net page with datalist, how to enumerate the list of rows?
the output is:
1. output1
1. output2
1. output3
1. output4
....
I need:
1. output1
2. output2
3. output3
4. output4
....
can you help me?
.cs
using System; using System.Configuration; using System.Data; using System.Data.Odbc; using System.Security.Cryptography; using System.Text; using System.Web.UI; using System.Web.UI.WebControls; public partial class areaRiservata_IstatOther : System.Web.UI.Page { OdbcConnection conn = new OdbcConnection(ConfigurationManager.ConnectionStrings["cs"].ConnectionString); string SQL; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Session["UserAuthentication"] == null) { Server.Transfer("Stopped.aspx"); } else { SQL = "SELECT * FROM "; SQL = SQL + "tbl_L "; SQL = SQL + "ORDER BY "; SQL = SQL + "total DESC;"; try { conn.Open(); OdbcCommand cmd = new OdbcCommand(SQL, conn); Other.DataSource = cmd.ExecuteReader(); Other.DataBind(); cmd.Dispose(); cmd = null; } catch (Exception ee) { throw ee; } finally { conn.Close(); } } } } }.aspx
<asp:DataList ID="Other" runat="server"> <ItemTemplate> <ol> <li> <asp:Image ID="lblflags" ImageUrl='<%# Eval("flags") %>' runat="server" /> <asp:Label ID="lblsource" runat="server" Text='<%# Eval("source") %>'></asp:Label> <asp:Label ID="lblTotal" runat="server" Text='<%# Eval("total") %>'></asp:Label> </li> </ol> </ItemTemplate> </asp:DataList>Rion William...
All-Star
27352 Points
4535 Posts
Re: [C# net 2] Datalist numbered list
Jan 29, 2013 05:17 PM|LINK
The reason this is occuring is that within your <ItemTemplate> you are creating a new <ol> element for each of the Items in your collection and adding a single <li> element within that Ordered List.
This explains the reason that you are receiving a "1." for each of your elements. You could try wrapping the DataList within an <ol> element :
<ol> <asp:DataList ID="Other" runat="server"> <ItemTemplate> <li> <!-- Your Output --> </li> </ItemTemplate> </asp:DataList> </ol>cms9651
Member
175 Points
573 Posts
Re: [C# net 2] Datalist numbered list
Jan 29, 2013 05:25 PM|LINK
ok thank you, solved with:
<ol> <asp:DataList ID="Other" runat="server"> <ItemTemplate> <li> *** </li> </ItemTemplate> </asp:DataList> </ol>Rion William...
All-Star
27352 Points
4535 Posts
Re: [C# net 2] Datalist numbered list
Jan 29, 2013 05:29 PM|LINK
Glad it worked out for you!
I was posting something similar but ran into some connection issues. It finally posted and wouldn't you know it, exactly what you had. :)