Pages

Tuesday, June 26, 2012

add Serial Number in gridview

sometimes we need to add serial numbers in gridview. we can achieve it through following code snippet.
<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.

Happy Coding!!

No comments:

Post a Comment