Click here to Skip to main content
15,891,621 members
Articles / Web Development / ASP.NET
Tip/Trick

Easy way to add Serial Numbers Column in Gridview

Rate me:
Please Sign up or sign in to vote.
3.54/5 (12 votes)
24 Mar 2010CPOL 39.3K   4  
May occasions we need to give Serial numbers to our grid like 1,2,3,4,5, this I have tried my hand for a while and what I found.....I have posted it in someones questions earlier. We can give alphabets also but its usage is limited so that part is omitted. (it is somewhat tedious...

May occasions we need to give Serial numbers to our grid like 1,2,3,4,5, this I have tried my hand for a while and what I found.....


I have posted it in someones questions earlier. We can give alphabets also but its usage is limited so that part is omitted. (it is somewhat tedious also).


ASP.NET
<asp:TemplateField>
            <HeaderTemplate>
            Serial No.</HeaderTemplate>
            <ItemTemplate>
            <asp:Label ID="lblSRNO" runat="server" 
                Text='<%#Container.DataItemIndex+1 %>'></asp:Label>
            </ItemTemplate>
            </asp:TemplateField>

This code works as same when we apply paging.


We cannot use this on BoundFields because they support only those objects who have Databinding event

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Junior) Excel Informatics, Pune
India India
Am Indrajeet T. Sutar. I am a web developer. I am working on .net technology. I have completed my Masters in Computers and Management (people call it as MCA, MBA etc.) Apart from programming i do photography (not regularly though), traveling and reading books.

Comments and Discussions

 
-- There are no messages in this forum --