Appending data into Listview control results
Posted
by strakastroukas
on Stack Overflow
See other posts from Stack Overflow
or by strakastroukas
Published on 2010-05-24T16:17:04Z
Indexed on
2010/05/24
16:31 UTC
Read the original article
Hit count: 311
In my webpage i use the following in order filling the listview control
<asp:ListView ID="ListView1" runat="server">
<layouttemplate>
<asp:PlaceHolder id="itemPlaceholder" runat="server" /></layouttemplate>
<ItemTemplate>
<tr>
<td><asp:Label ID="Label1" runat="server" Text = '<%# DataBinder.Eval(Container.DataItem, "Ans1") %>' Visible = '<%# DataBinder.Eval(Container.DataItem, "Ans1Visible") %>'></asp:Label>
<br />
<asp:Label ID="Label2" runat="server" Text = '<%# DataBinder.Eval(Container.DataItem, "Ans2") %>' Visible = '<%# DataBinder.Eval(Container.DataItem, "Ans2Visible") %>'></asp:Label>
<br />
<asp:Label ID="Label3" runat="server" Text = '<%# DataBinder.Eval(Container.DataItem, "Ans3") %>' Visible = '<%# DataBinder.Eval(Container.DataItem, "Ans3Visible") %>'></asp:Label>
<br />
<asp:Label ID="Label4" runat="server" Text = '<%# DataBinder.Eval(Container.DataItem, "Ans4") %>' Visible = '<%# DataBinder.Eval(Container.DataItem, "Ans4Visible") %>'></asp:Label>
<br />
<asp:Label ID="Label5" runat="server" Text = '<%# DataBinder.Eval(Container.DataItem, "Ans5") %>' Visible = '<%# DataBinder.Eval(Container.DataItem, "Ans5Visible") %>'></asp:Label>
<br />
<asp:Label ID="Label6" runat="server" Text = '<%# DataBinder.Eval(Container.DataItem, "Ans6") %>' Visible = '<%# DataBinder.Eval(Container.DataItem, "Ans6Visible") %>'></asp:Label>
</td>
</tr>
</ItemTemplate>
</asp:ListView>
Now i would like to add numbers to the labels before they are rendered.
For example currently the data displayed are like
Tennis
Football
Basketball
Nfl
Nba
Polo
and the output i would like to have is
1. Tennis
2. Football
3. Basketball
4. Nfl
5. Nba
6. Polo
Could i use ListView1_ItemCreated or the ListView1_ItemDataBound event to achieve this? If that is true, could you point me a place to start?
© Stack Overflow or respective owner