If it is just for display, not for changing the serial number in the database, try a TemplateField column like this:
C# Example:
<asp:TemplateField HeaderText="S.NO"> <ItemStyle Width="30px" />
<ItemTemplate>
<%# Container.DataItemIndex + 1 %>.
</ItemTemplate>
</asp:TemplateField>
VB.Net Example:
VB.NET:
<asp:TemplateField HeaderText="S.No" >
<ItemTemplate>
<%# CType(Container, GridViewRow).RowIndex + 1%>
</ItemTemplate>
</asp:TemplateField>
<ItemTemplate>
<%# CType(Container, GridViewRow).RowIndex + 1%>
</ItemTemplate>
</asp:TemplateField>
C#:
Hi this is really good idea have a look of this
ReplyDeletehttp://www.dotnetpools.com/2013/10/auto-generate-row-number-in-gridview-in.html