Show Rownumber In ASP.net Datagrid

It is often useful to show a rownumber in a datagrid. For example if you have a list of things that are displayed in “Rank order”. How can we do this? It’s pretty easy actually. Just add the below column definition to your datagrid in order to show the rownumber.

<asp:templatecolumn headertext=”Row Number”>
 <itemtemplate>
  <span><%# Container.ItemIndex+1 %></span>
 </itemtemplate>
</asp:templatecolumn>  

Leave a Reply

Your email address will not be published. Required fields are marked *