Simple ways to Auto Generate Serial Number in GridView - An Example
Introduction
Sometimes we have a scenario to create a column that will auto generate the serial number, so in this post I will explain how to generate serial number in Grid View.
Simple ways to Auto Generate serial number in GridView
- You can do using Container.DataItemIndex in GridView
<asp:TemplateField HeaderText="Serial No">
<ItemTemplate>
<%#Container.DataItemIndex + 1 %>
</ItemTemplate>
</asp:TemplateField>
- You can add following line of code to auto generate a column in GridView
<asp:TemplateField HeaderText="Serial No">
<ItemTemplate>
<asp:Label ID="Label1" runat="server"
Text='<%# (GridView1.PageSize * GridView1.PageIndex) + Container.DisplayIndex + 1 %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
No comments:
Post a Comment