Easy way to add Serial Numbers Column in Gridview






3.54/5 (12 votes)
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: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