How to display row number in Row header of DataGrid

by Viper 12. January 2009 08:17

Lot of time you want to display line number (row index) of rows in DataGrid in Row header of your grid very much like how each row in Microsoft Excel displays line number. One dirty solution is to add a new column in the grid at first position and then display its text as row number. There is more elegant solution available. You can actually set the Row.Header value to Row index in LoadingRow event of your grid.

protected GridRowLoading(object sender, DataGridRowEventArgs arg)
{
  arg.Row.Header = arg.Row.GetIndex();
}

Make sure that you set HeaderVisibility property of your grid to "Row" or "All". By default row header is not visible.

Views: 1425

Tags:

ASP.Net | Silverlight | DataGrid

Comments

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.5.1.7
Theme by Naveen Kohli

Recent

By Categories