TKCAdmin posted on August 31, 2010 10:16

Using the objectdatasource with griddview or detailsview controls for selecting, inserting, updatingand deleting data.
Detailsview Annoyances and Peculiarities
When the DetailsView is not bound to a data source control you don't get newvalues and oldvalues in the updating event like you do when it is bound.
Hide fields in detailsview:
Detailsview.Fields(GetFieldIndexByHeader(Detailsview, "ViewName")).Visible = False
Get a field value from DetailsView:
- Rows index in the detailsview represents each label and value pair going down the control.
- Cells index in the detailsview is 0 for the row’s label and 1 for the row’s value
So to get the value in the third row you would use:
strValue = Detailsview.Rows(3).cells(1).text
ObjectDataSource
You can use an object as the parameter for inserts, updates and deletes but you must:
1) Fill in the DataObjectTypeName property on the objectdatasource with the typename of the parameter
2) Only have one parameter (the object) for insert, update or delete. The select method can have different parameters to the object.
3) When using a method for update, insert or delete, the parameters of the method or the properties of the object parameter will automatically map to columns on the corresponding detailsview or gridview if they have exactly the same names.
How to modify an object parameter in a DetailsView when it’s bound to the ObjectDataSource:
Protected Sub objdsMyDataSource _Inserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs) Handles objdsMyDataSource.Inserting
Dim objMyObject As MyObjectType
Dim intPropertyValue As integer = 10
objMyObject = e.InputParameters("objMyObject")
objMyObject.MyProperty = intPropertyValue