views:

21

answers:

1

Has anyone come across an error like the following:

Unable to cast object of type 'CompaniesDataTable' to type 'CompaniesDataTable'.

Here is the code that is causing the error:

    protected void ObjectDataSource_Companies_Selected(object sender, ObjectDataSourceStatusEventArgs e)
    {
        int x = ((Adala.CompaniesDataTable)(e.ReturnValue)).Count;
    }

What I'm trying to do is to get the total number of rows of gridview returned by the objectdatasource but it gives me that error.

Why is it not able to cast type to the same type?

A: 

OK Thanks Shaji for not answering, Any way I found a solution for my problem.

I created a BLL Class and instantiated it instead of Direct Instantiating Dataset Classes.

inside BLL i created this method

public Adala.CompaniesDataTable GetCompanies(out int rowsCount)
{
    Adala.CompaniesDataTable dt = Adapter.GetCompanies();
    rowsCount = dt.Count;
    return dt;
}

then i can use the property e.OutputParameters["rowsCount"].ToString(); in the Method Objectdatasource.Selected event

protected void ObjectDataSource_Companies_Selected(object sender, ObjectDataSourceStatusEventArgs e)
{
    string rowsCount = e.OutputParameters["rowsCount"].ToString();
}
Mohamed S. Abu Emesh