Add auto number column in Gridview in asp.net

No.of Views2169
Bookmarked0 times
Downloads 
Votes0
By  Prajeesh   On  26 May 2010 08:05:22
Tag : ASP.NET , Grid Controls
In many situations we may need to add auto number or serial numbers in grid view column, but we cannot find a property in property window to add this.
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Introduction

In many situations we may need to add auto number or serial numbers in grid view column, but we cannot find a property in property window to add this.

We can add auto number column in Grid view or Data List by using Container.DataItemIndex property in Gridview or Data List mark up.

Add a Template field and add following code in Grid view Mark up:

 Implementation

<asp:TemplateField HeaderText="Serial Number">
<ItemTemplate>
<%# Container.DataItemIndex + 1 %>
</ItemTemplate>
</asp:TemplateField>

enjoy this small code snippet.

 
Sign Up to vote for this article
 
About Author
 
Prajeesh
Occupation-Not Provided
Company-Not Provided
Member Type-Fresh
Location-India
Joined date-15 May 2010
Home Page-Not Provided
Blog Page-Not Provided
 
 
Other popularSectionarticles
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top