Accessing the data or dataItem used to bind a gridview?

MyGridView.Rowse.RowIndex. DataItem should generally work but I guess that you are probably relying the view-state for retaining grid data on post-backs. In such case, you will get the DataItem property as NULL Work-around can be to always re-bind the grid with actual data in each postback early in page life cycle (say page_load ) However, in your case, you can very well use DataKeyNames Contrary to your belief, you don't need a DataTable for this property to work.

For example, if your class has property named ItemId indicating the key for your object then you can use DataKeyNames="ItemId in the markup and refer it in OnRowDeleting using Keys property of event arguments.

MyGridView.Rowse.RowIndex. DataItem should generally work but I guess that you are probably relying the view-state for retaining grid data on post-backs. In such case, you will get the DataItem property as NULL.

Work-around can be to always re-bind the grid with actual data in each postback early in page life cycle (say page_load). However, in your case, you can very well use DataKeyNames. Contrary to your belief, you don't need a DataTable for this property to work.

For example, if your class has property named ItemId indicating the key for your object then you can use DataKeyNames="ItemId" in the markup and refer it in OnRowDeleting using Keys property of event arguments.

ViewState isn't used, however other things are saved in Session state. To use the DataKeyNames the propertys must be serializable correct? – Teletha Aug 17 at 10:27 @teletha, actual data key values are stored in control-state (or view-state) so yes-your key property type has to be serializable.

But most often, your key properties will be combination of int, string, guid and those are already marked as serializable. – VinayC Aug 17 at 10:43 I see! These key values, are they the propertys of the DataItem that is being bound or how do I set/get these?

Can I e g give a name to a row in the ItemTemplete? – Teletha Aug 17 at 11:22 @Teletha, assuming you are binding your grid with the collection of objects of type 'MyItem' and if this class has a property called 'ItemId' then you have to set DataKeyNames="ItemId" at gridview level then Keys property of GridViewDeleteEventArgs will have value of this property for the object bound to the row being deleted. – VinayC Aug 17 at 12:10.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions