Serial No in GridView
So many time this question has been asked in forum regarding serial No display in gridview. I just know one work around like this way. Not sure if anybody already posted this before. So, main logic is to add DataItemIndex with plus one in Template field.
<%# Container.DataItemIndex + 1 %> |
html mark up look like this.
<asp:GridView ID="GridView1" runat="server" DataSourceID="objCustomer"> <Columns> <asp:TemplateField HeaderText="Serial No"> <ItemTemplate> <asp:Label ID="lblNo" runat="server" Text='<%# Container.DataItemIndex + 1 %>'/> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> <asp:ObjectDataSource ID="objCustomer" TypeName="Customer" SelectMethod="GetCustomer" runat="server" /> |
Out put look like below one :-