473,396 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Container.ItemIndex

Using SqlDataAdapter, I am retrieving records from a SQL Server 2005 DB
table & binding them to a DataList. In the DataList, I want the first
column to display the serial numbers starting from 1. I am doing this
using the following code:

<asp:DataList ID="dList" runat="server">
<HeaderTemplate>
<table border="2">
<tr>
<th>#</th>
<th>Col1</th>
<th>Col2</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><asp:Label ID="lblSNo" Text="<%# Container.ItemIndex + 1 %>"
runat="server"/></td>
<td><asp:Label ID="lblCol1" Text="<%# Container.DataItem("Col1") %>"
runat="server"/></td>
<td><asp:Label ID="lblCol2" Text="<%# Container.DataItem("Col2") %>"
runat="server"/></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:DataList>

Assuming that 4 records have been retrieved, the 4 Labels under the
first column for the 4 rows render the text 1, 2, 3 & 4 respectively.
Next I change the first Label code to

<td><asp:Label ID="lblSNo" Text="<%# Container.ItemIndex + 1 %>."
runat="server"/></td>

Note the "." (dot) within the Text property of the Label whose ID is
lblSNo. Now the 4 Labels for the 4 rows under the first column do not
render the text 1, 2, 3 & 4. Instead all the 4 Labels just render the
text "." (without the quotes) in the 4 rows under the first column.
Why?

Of course, I can overcome this trivial problem by placing the "."
immediately after the first Label tag closes i.e. just before the
closing </tdtag like this

<td><asp:Label ID="lblSNo" Text="<%# Container.ItemIndex + 1 %>"
runat="server"/>.</td>

but I did like to know why don't the 4 Labels render the text 1, 2, 3 &
4 when a "." is added within the Text property of the first Label.

Nov 20 '06 #1
0 8106

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: jignesh shah | last post by:
Hi all, Is there a way to recover a single container if its been corrupted or mark bad without restoring whole tablespace? environment: db28.1/aix5.1/tsm/rs-6000. Regards Jignesh
0
by: Barry | last post by:
Hi, I have a sub in a user control that looks like this: Public Sub BatchDetail_ItemCommand(ByVal Sender As Object, ByVal e As DataListCommandEventArgs) Dim cmd As String =...
3
by: Stephan | last post by:
Hi, I'm working on a page with multiple Datalist-controls on it. The problem I'm facing is that when I try to update a record, the ItemIndex returns a value which is one lower than the Item I...
0
by: brian yeo via .NET 247 | last post by:
I could not fetch "userID/column0" since my datagrid does not usethe DataKeyField (due to reformatting of dates - not shown). TheItemIndex can be located from clicking Edit button. How do Iread the...
3
by: Adam Knight | last post by:
Hi all, I have asked this question previously, but haven't recieved an adequate answer. I am wanting to output a datalist ItemIndex in a page. I know to display a data item i using <%#...
1
by: chandy | last post by:
Hi, I need to be able to move individual rows up and down in my datagrid. the ItemIndex property of the DataGridItem is ReadOnly so how can this be accomplished? Manual recreation of the dataset...
9
by: horizon5 | last post by:
Hi, my collegues and I recently held a coding style review. All of the code we produced is used in house on a commerical project. One of the minor issues I raised was the common idiom of...
5
by: Brad Baker | last post by:
I am trying to make a "tabbed" interface by iterating through a dataset with a conditional statement. For example: ...
2
by: Rod | last post by:
While working with a datagrid I have a value for the datakey, from this I want to find the ItemIndex. How please? many thanks in advance.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.