I often want my GridViews to have the first column just be a number identifying the row. I see this beneficial because:
- The user can see the number of rows returned by scrolling to the end of the GridView
- If there are two people looking at the GridView, they can say “look at item #5 …”
To make this happen you need to add this element to the <columns> element of your GridView:
<asp:GridView ...> <Columns> <asp:TemplateField> <ItemTemplate> <%# Container.DataItemIndex + 1 %>. </ItemTemplate> <ItemStyle HorizontalAlign="Right" /> </asp:TemplateField> ... </Columns> ... </asp:GridView>
This looks weird if paging is on. But you can tweak the math to make it work right.