views:

160

answers:

2

I am using an ObjectDataSource control to call a MapInfo object. This object has two properties:

  • public IList Visits
  • public int TotalAvailable

The select method returns an IList but the TotalAvailable property is also populated. I have set the TypeName in the ObjectDataSource to the MapInfo object but because the Select method only returns the IList I don't have access to the TotalAvailable.

[DataObject(true)]
public sealed class MapInfo
{
    private IList<Visit> visits;
    private int totalCount;

    public IList<Visit> Visits
    {
        get
        {
            if (visits == null)
                visits = new List<Visit>();
            return visits;
        }
        set
        {
            visits = value;
        }
    }

    [DataObjectMethod(DataObjectMethodType.Select)]
    public IList<Visit> GetAccountVisits(DateTime startdate, DateTime enddate, string orgids, int reportlevel,
         string username, int authlevel, bool visited, bool notvisited, string accounttypeid)
    {

}

Is there any way to access this value. I know it is being populated in the MapInfo object but all that gets returned from the Select method is the IList

A: 

Hey,

that datasource fires a Selected event after the select happens; you could try to see if it exposes the root object there.

HTH.

Brian
It doesn't. It just brings back the returned values from the SelectMethod.
Ryan Tomlinson
Yeah I tried that. But again the ObjectDataSource seems to only return the return type and not the root object specified in the TypeName property.As above I have changed the return type and altered the connecting control to databind to the child objects.
Ryan Tomlinson
Your other option is to add a MapInfo property to the Visit class, which references the parent. This way, it would retain this relationship.
Brian
A: 

I have changed the return type of the SelectMethod to:

[DataObjectMethod(DataObjectMethodType.Select)]
public MapInfo GetAccountVisits(DateTime startdate, DateTime enddate, string orgids, int reportlevel,
     string username, int authlevel, bool visited, bool notvisited, string accounttypeid)
{

In my CompositeDataBoundControl in the CreateChildControls method, I then use:

DataBinder.Eval(((object[])(dataSource))[0], "Visits");

Would appreciate a more elegant solution though.

Ryan Tomlinson