C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » ASP.NET/Web Applications »

Adding Row Numbers


Posted Date: 13 Mar 2004    Resource Type: Articles    Category: ASP.NET/Web Applications
Author: SivaMember Level: Gold    
Rating: 1 out of 5Points: 7



Users often ask for the look and feel of Microsoft Excel in an application's data grid. One feature requested often is a set of row numbers on the grid. Using DataGrid's OnItemCreate event allows a sequential set of numbers to be added to the grid as each row is rendered.

Add a template column as the first column of the grid. As each row is rendered, the code behind the OnItemCreate event will update the text of this column based on the row index from the dataset. Each row of the dataset has an index property that can be used to compute the row number:

public void OnItemCreated(Object sender,
DataGridItemEventArgs e)
{
if(e.Item.ItemType ==ListItemType.Item ||
e.Item.ItemType ==ListItemType.AlternatingItem)
e.Item.Cells[0].Text=(e.Item.DataSetIndex+1).ToString();
}




Responses

Author: Sigen Oline Sørensen    01 Apr 2005Member Level: Bronze   Points : 0
Hey, nice trick ... I'm just starting up on .Net and I looked for this feature for some time - I could not get it to work, so I messed around with it and came up with this instead :








It seems easier to me, especially since I have to make a TemplateColumn no matter wich version I use !

Just my 2 cents,

Signe



Author: Sigen Oline Sørensen    01 Apr 2005Member Level: Bronze   Points : 0
I did not know that html would not be rendered ...heres is the code...

[Columns]
[asp:TemplateColumn HeaderText="#"]
[ItemTemplate]
[asp:Label Text='[%# Container.DataSetIndex + 1 %]' runat="server" /]
[/ItemTemplate]
[/asp:TemplateColumn]



Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Cause button click on Enter
Previous Resource: Localizing The Application
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET/Web Applications


Post resources and earn money!
 
Related Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use