1
votes

I created a UserControl with ObjectDataSource + ASPxGridView. SelectMethod of ObjectDataSource I set the dynamicly depending on public parameter of UserControl:

private int _companyID = -1;
public int CompanyID
{
    get { return _companyID; }
    set
    {
        _companyID = value;

        dsPersons.SelectMethod = "GetPersonsByCompany";
        dsPersons.SortParameterName = "sort";
        dsPersons.SelectParameters.Clear();
        dsPersons.SelectParameters.Add("companyID", DbType.Int32, value.ToString());
    }
}

When I use my control on Page like this:

<uc:PersonsManager ID="personsManager" runat="server" CompanyID="2" />

or put it in another ASPxGridView like this:

<dxwgv:ASPxGridView ID="gridViewCompany" runat="server" DataSourceID="dsCompany" KeyFieldName="ID" Width="100%"
    AutoGenerateColumns="false">
    <Columns>
        <dxwgv:GridViewDataColumn>
            <DataItemTemplate>
                <uc:PersonsManager ID="personsManager" runat="server" CompanyID='<%# Bind("ID") %>' />
            </DataItemTemplate>
        </dxwgv:GridViewDataColumn>
    </Columns>
</dxwgv:ASPxGridView>

All works fine, but I wanna to declare Control parameter from code-behind:

<uc:PersonsManager ID="personsManager" runat="server" />

and then on Page_Load:

personsManager.CompanyID = 2;

And if I use previous declaration then I can see only first load of UserControl's ASPxGridView with some data, because any manipulation will cause error on HtmlRowCreated event of UserControl's ASPxGridView:

The Select operation is not supported by ObjectDataSource 'dsPersons' unless the SelectMethod is specified.

Why is this happening?

Thanks.

2

2 Answers

0
votes

When you add the object datasource, you are presented with a wizard that lets you select the methdods on your object that support the typical CRUD methods of the database.

Click the smarttag of your objectDataSource and select 'configure datasource' and you will see.

THen take a look at http://msdn.microsoft.com/en-us/library/9a4kyhcx.aspx to learn how to implement those methods..

good luck.

0
votes

Have a look at this blog post "Manually Set ObjectDataSource.SelectMethod Property BUG" by Eran Nachum. He describes how you must set the grid's datasource during the OnInit event and then do the databinding during OnPreRender.

(The website referenced above is no longer active. There is a copy of the blog post on the wayback machine: Eran Nachum's Blog from December 2007 in the wayback machine)