Hi ,
You can create a attribute with AutoNumber field in the entity connected to the datagrid or
You can create a seperate attribute with integer type and increement it when ever new data saved for that entity.
This forum post is about the same issue and it provides a solution (though it includes Javascript, you'll have to see if that is the kind of solution you're looking for).