
In this article, we will look at a technique that will allow us to generate row numbers in the first column of a DataGrid. To generate the row numbers, we will use the DataGridItem's ItemIndex property. Nikhil Kothari (ASP.NET team member extraordinaire) was kind enough to inform me that the ItemIndex property was created for just such a scenario. As such, the sample below is very simple. We will create an extra TemplateColumn in our DataGrid and bind to it the value of Container.ItemIndex. The ItemIndex property is zero based so we will add one to it and voila, we have a row counter in our DataGrid.
|