I'm trying to use a RadGrid control with a manual datasource. Tthat is, I do not have a DataSource control on the page, instead I use the NeedDataSource event to wire it up to a DataTable that is retrieved through some custom code. The DataTable is is stashed in ViewState the first time and then retrieved on this event as needed.
Now, it's pretty straightforward to add a column to the RadGrid that adds an Edit link that puts the row into edit mode and that action column now has Update/Cancel links. I can also see how easy it ease to add a AddNewRecords attribute to the CommandItemsSettings element.
And of course, wire up actions to the ItemCommand event or the individual UpdateCommand, DeleteCommand, etc. events. So far so good. What took quite a bit of digging into example code to find was the way to retrieve a reference to the row that was inserted/edited/deleted. There seems to be a variety of ways, but the one I see most in example code is:
I have to tell you... I would never have figured this out w/out digging into existing code samples! This does not seem intuitive at all, and so far, I haven't really come across any narratives or field notes or just plain english description about this. Specifically, I'm not sure I understand the OwnerTableView bit of it.
From the example above, why can't I just use the editItem.ItemIndex value to tell me which row in my datasource I'm on? Then get that just index into it using something like
I've also seen some sample code that does something like:
To me, both of the above examples are fairly easy to understand.
Any guidance (with some explanation) on what the various methods are would be appreciated. Any info on the object chain that requires this OwnerTableView reference would also be greatly appreciated. I realize I can just copy/paste the code and go on, but I'd really like to *understand* what I'm doing here!
Thanks.
Now, it's pretty straightforward to add a column to the RadGrid that adds an Edit link that puts the row into edit mode and that action column now has Update/Cancel links. I can also see how easy it ease to add a AddNewRecords attribute to the CommandItemsSettings element.
And of course, wire up actions to the ItemCommand event or the individual UpdateCommand, DeleteCommand, etc. events. So far so good. What took quite a bit of digging into example code to find was the way to retrieve a reference to the row that was inserted/edited/deleted. There seems to be a variety of ways, but the one I see most in example code is:
GridEditableItem eeditItem = e.Item as GridEditableItem; |
string str = editItem.OwnerTableView.DataKeyValues[editItem.ItemIndex]["EntityID"].ToString(); |
I have to tell you... I would never have figured this out w/out digging into existing code samples! This does not seem intuitive at all, and so far, I haven't really come across any narratives or field notes or just plain english description about this. Specifically, I'm not sure I understand the OwnerTableView bit of it.
From the example above, why can't I just use the editItem.ItemIndex value to tell me which row in my datasource I'm on? Then get that just index into it using something like
DataTable dt = GridSource; |
GridEditableItem eeditItem = e.Item as GridEditableItem; |
DataRow myRow = dt.Rows[editItem.ItemIndex]; |
I've also seen some sample code that does something like:
GridDataItem item = (GridDataItem)e.Item; |
string str = item["CompanyName"].Text; |
To me, both of the above examples are fairly easy to understand.
Any guidance (with some explanation) on what the various methods are would be appreciated. Any info on the object chain that requires this OwnerTableView reference would also be greatly appreciated. I realize I can just copy/paste the code and go on, but I'd really like to *understand* what I'm doing here!
Thanks.