Home>

In asp.net, if i want to display the serial number in the gridview list,No need to write your own method to get the serial number,This can be achieved by adding 1 to the container.dataitemindex property,Binding in the list is ok!

Example code:

<asp:gridview runat="server" width="100%">
  <columns>
    <asp:templatefield headertext="serial number" headerstyle-width="10%">
      <itemtemplate>
        <%#(container.dataitemindex + 1) .tostring ()%>
      </itemtemplate>
    </asp:templatefield>
    <asp:templatefield headertext="city">
      <itemtemplate>
        <%#eval ("city"). Tostring ()%>
      </itemtemplate>
    </asp:templatefield>
    <asp:templatefield headertext="company name">
      <itemtemplate>
          <%#eval ("com_name")%>
      </itemtemplate>
    </asp:templatefield>
  </columns>
</asp:gridview>

Display of results:

Isn't the implementation method very simple,If the project needs to display the serial number in the gridview list,Just follow the instructions above to get started!

  • Previous Tips for using multi-port access under WampServer
  • Next Difference between iOS's UIColor class and its related classes and methods for determining equality