Serial number in Gridview or datalist in asp.net

For add new column we can add AutoNumber column by using Container.DataItemIndex property in Gridview like as follows:

<asp:GridView ID="GridViewMyGrid" runat="server"  AllowPaging="True" AutoGenerateColumns="False"
PageSize="10">
<Columns>
    <asp:TemplateField HeaderText="Serial Number">
        <ItemTemplate>
            <%# Container.DataItemIndex + 1 %>
        </ItemTemplate>
    </asp:TemplateField>
   
    <asp:BoundField DataField="Dept_Id" HeaderText="Department Id"/>
    <asp:BoundField DataField="Dept_Name" HeaderText="Department Name"/>

     //.....
     //.....
    
    </Columns>
</asp:GridView>
Ebook Download
View all
Learn
View all