Specifying the Serial number in the GridView in ASP.Net

you just need to add the following code as the first template field of the GridView:

<asp:TemplateField>
    <HeaderTemplate>
        Serial No.
    </HeaderTemplate>
    <ItemTemplate>
        <%# Container.DataItemIndex + 1 %>
    </ItemTemplate>
</asp:TemplateField>

Complete code for the GridView becomes

<asp:GridView ID="GridView1" runat="server"
    AutoGenerateColumns="False" CellPadding="4" 
    ForeColor="#333333" GridLines="None" 
    onpageindexchanging="GridView1_PageIndexChanging" 
    Width="180%" Font-Size="Medium" PageSize="19" 
    onrowdatabound="GridView1_RowDataBound">
                    
    <Columns>
        <asp:TemplateField>
              <HeaderTemplate>
                        Serial No.
              </HeaderTemplate>
              <ItemTemplate>
                  <%# Container.DataItemIndex + 1 %>
              </ItemTemplate>
          </asp:TemplateField>

        <asp:BoundField DataField="TYPE" HeaderText="Type" />
        <asp:BoundField DataField="CHANNEL" HeaderText="Chanel" />
        <asp:BoundField DataField="CALLERID" HeaderText="Caller ID" />
        <asp:BoundField DataField="RECEIVED_STATUS" HeaderText="CallStatus" />
        <asp:BoundField DataField="REMARK" HeaderText="Remark" />
    </Columns>
</asp:GridView>
Ebook Download
View all
Learn
View all