In asp.net, if you want to display the serial number in the GridView list, you don't need to write a method to get the serial number, you can do it by adding 1 to the Container.dataitemindex attribute, and the binding is OK in the list!
Instance code:
<asp:gridview id= "gvlist" runat= "Server" width= "100%" >
<Columns>
<asp:templatefield headertext= "Serial number" headerstyle-width= "10%" >
<ItemTemplate>
<%# (Container.dataitemindex + 1). ToString ()%>
</ItemTemplate>
</asp:TemplateField>
<asp:templatefield headertext= " Shi ' an >
<ItemTemplate>
<%# Eval ("City"). ToString ()%>
</ItemTemplate>
</asp:TemplateField>
<asp:templatefield headertext= "Enterprise Name" >
<ItemTemplate>
<%# Eval ("Com_name")%>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Show Effect:
is the implementation of the method is very simple, if the project needs to implement the GridView list to display the serial number, follow the above practice to do it!