Powered by Blogger.

Friday, February 14, 2014

How to display serial number automatically in GridView in asp.net?



In this post we will discuss how to display a serial number column in gridview in asp.net. Also you can check my previous posts on:

- Steps to create wcf service and host wcf service as windows service in C#.Net

- Tutorial on WPF Controls and Layout

- Working with enterprise library for data access in asp.net Part-3

Serial number will come as an index, it will start from 1 and will go on increasing 1 value for each row.

Here the code to bind a gridview will be same. Only thing will change is we need to another <ItemTemplate> like below:

<asp:GridView ID="GridView1" runat="server">
        <Columns>
            <asp:TemplateField HeaderText="Serial Number">
                <ItemTemplate>
                    <%# Container.DataItemIndex + 1 %>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>

If you will write this code then the serial number column will come.





0 comments

Post a Comment