Can i have a Row Counter in a Bounded DataGrid?

R

RSB

Hi I Want to Bind the DataGrid with the Collection i have and want to
display a RowCounter 1,2,3,4,... in the First Column.. how to Do this??
Does Datagrid Provides any property etc.etc.??

Thank You

RSB
 
R

Rathga

A sneaky way is to databind to a protected int with an increment operator:

<templatecolumn etc..> <%#i++%> </...>

Each time the integer is accessed by the databinding code it increments by
one, which produces the desired effect.

rath.
 
J

John Saunders

RSB said:
Hi I Want to Bind the DataGrid with the Collection i have and want to
display a RowCounter 1,2,3,4,... in the First Column.. how to Do this??
Does Datagrid Provides any property etc.etc.??

The ItemDataBound event of the DataGrid will be raised once per row in the
grid. You can use the EventArgs to get access to the Item being bound, and
therefore, to the ItemIndex:

private void myGrid_ItemDataBound(object sender, DataGridItemEventArgs e)
{
// e.Item.ItemIndex is the index of the item being DataBound
}

You could add a TemplateColumn as your first column, and it could contain a
Label control. You could set the text of the label to ItemIndex.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top