How to display the serial number of the GridView Control
In ASP. NET, if you want to display the serial number in the GridView list, you do not need to write the method to obtain the serial number, through Container. you can add 1 to the DataItemIndex attribute and bind it to the list!
Instance code:
<Asp: GridView ID = "gvList" runat = "server" Width = "100%"> <Columns> <asp: templateField HeaderText = "no." HeaderStyle-Width = "10%"> <ItemTemplate> <% # (Container. dataItemIndex + 1 ). toString () %> </ItemTemplate> </asp: TemplateField> <asp: TemplateField HeaderText = ""> <ItemTemplate> <% # Eval ("City "). toString () %> </ItemTemplate> </asp: TemplateField> <asp: TemplateField HeaderText = "enterprise name"> <ItemTemplate> <% # Eval ("Com_Name ") %> </ItemTemplate> </asp: TemplateField> </Columns> </asp: GridView>
Display Effect:
The implementation method is very simple. If you need to display the serial number in the GridView list in the project, follow the above practice to implement it!