Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Still not able to Update witn ObjectDataSource
Message
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Miscellaneous
Thread ID:
01248155
Message ID:
01248915
Views:
23
>Greetings Kevin,
>
>Thanks, this is very helpful. Does the ODS cache the object it's based on (i.e an EntityList)? In other words, can I get access to the original entity item throught the ODS or do I need Cache, Session, or requery to get the original entity the GridView Row was based on?

E.R.

Realistically - why would you use an object data source if you are already using business objects proper? With the databinding in MM and the update mechanisms you'll be much better off implementing your own databinding than working with the funky ODS model.

+++ Rick ---

>
>Regards,
>
>E.R.
>
>>E.R.,
>>
>>>Right now the GridView is trying to hit an update method with parameters it is generating based on the columns in the GridView. What I was trying to find out from you was if there was a default update method one could specify for updating or if I will have to create a method for each Biz obj that maps to columns use in any GridView that use that biz obj. If that's the case fine, but with no documentation on using the ODS I didn't want to create all these methods and then find out later there was an easier way.
>>
>>There is no built-in method in MM .NET that accepts discrete parameters for updating, so if you want to use that appraoch you need to create custom methods on each object. That said, it's cumbersome to create and maintain a method that accepts a parameter for each grid column. Alternately, you can create a business object method that accepts an entity object of a specfic type. Here is an excerpt from an MSDN help topic (http://msdn2.microsoft.com/en-us/library/57hkzhy5.aspx):
>>
>>Most business object method signatures take parameters of type String and Int32. However, you might be working with a business object method that takes one or more parameters typed as a complex or user-defined type. To work with complex or user-defined parameter types, you can use the ObjectDataSource control's DataObjectTypeName property.
>>
>>In your business object, creating methods with long parameter lists that map control values one-to-one to data store values can result in code that is not easily reusable. A better practice is to encapsulate your data in a custom class and then pass an instance of the class as a parameter. That way, the data that makes up an instance of the class, such as an employee record, can change without requiring any changes to the public interfaces exposed by the data source object. The following code example shows a class named NorthwindExployee that defines the employee data and that can be passed as a parameter to a business object.
>>
>>C#
>>
public class NorthwindEmployee {
>>    public NorthwindEmployee() { }
>>    private int _empId;
>>    private string _firstName;
>>    public int EmpId {
>>      get { return _empId; }
>>      set { _empId = value; }
>>    }
>>    public string FirstName {
>>      get { return _firstName; }
>>      set { _firstName = value; }
>>    }
>>    // Additional code for the class.
>>}
>>
>>Visual Basic
>>
Public Class NorthwindEmployee
>>    Public Sub New()
>>    End Sub
>>
>>    Private _empId As String
>>    Public Property EmpId() As Integer
>>        Get
>>            Return _empId
>>        End Get
>>        Set
>>            _empId = value
>>        End Set
>>    End Property
>>
>>    Private _firstName As String
>>    Public Property FirstName() As String
>>        Get
>>            Return _firstName
>>        End Get
>>        Set
>>            _firstName = value
>>        End Set
>>    End Property
>>
>>    ' Additional code for the class.
>>End Class
>>
>>To accept an instance of the preceding class as a parameter, the business object's UpdateEmployeeInfo method might be defined using the following signature:
>>
>>C#
>>
public void UpdateEmployeeInfo(NorthwindEmployee emp) {
>>}
>>
>>
Visual Basic Copy Code
>>Public Sub UpdateEmployeeInfo(emp As NorthwindEmployee)
>>End Sub
>>
>>Although you cannot set the Type of a parameter to the name of a custom class, you can set the ObjectDataSource control's DataObjectTypeName property to the name of a custom user-defined type, such as the NorthwindEmployee class, and then pass an instance of the type to a business object data method. To pass user-defined objects to a data source object, the following conditions must be met:
>>
>>
  • The user-defined type must have a default constructor (a constructor that takes no parameters).
    >>
    >>
  • The user-defined type must define public properties whose names match those of the dictionary entries passed to the data source control from data-bound controls such as GridView and DetailsView. For details about these dictionaries, see Using Parameters with Data Source Controls.
    >>
    >>
  • The data source object's public properties must expose both get and set accessors.

      >>
      >>The following example shows an ObjectDataSource control that performs an update operation by calling the UpdateEmployeeInfo method of a business object named EmployeeLogic. The ObjectDataSource control is configured to pass an instance of the NorthwindEmployee class to the update method.
      >>
      >>
      <asp:objectdatasource
      >>  runat="server"
      >>  id="ObjectDataSource1"
      >>  typename="EmployeeLogic"
      >>  selectmethod="GetAllEmployees"
      >>  updatemethod="UpdateEmployeeInfo"
      >>  dataobjecttypename="NorthwindEmployee" />
      >>
      >>In some cases, the business object method will have a parameter list that contains multiple complex parameter types. In that case, you can use the ObjectDataSource control, but you must add your parameters to the ObjectDataSource control programmatically. To do this, handle the event that is raised before the data operation is performed, such as the Inserting, Updating, or Deleting event, and set values in the InputParameters collection exposed by the ObjectDataSourceMethodEventArgs class.
      >>
      >>Best Regards,
      +++ Rick ---

      West Wind Technologies
      Maui, Hawaii

      west-wind.com/
      West Wind Message Board
      Rick's Web Log
      Markdown Monster
      ---
      Making waves on the Web

      Where do you want to surf today?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform