views:

454

answers:

2

Hello all,

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.

A: 

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.

Sky Sanders
You didn't understand the situation properly: my methods works fine when I set Control parameter inline or inside other gridView (Bind), but it doesn't work when I set parameter from code-behind (c#).I think that the problem in ASPxGridView and it's callback, why Page_Load is ignored?
Jo Asakura
I was a bit confused, the binding is happening after page-load. The parameters are still set in the markup, right? and you are wanting to override them? you may have to handle the onselect or selecting or whatever method and build it up yourself to get around that. again, i am vaguely recollecting but I know I have been there more than once...
Sky Sanders
Hm... I have a custom control on page (nothing else). UserControl have a gridView and dataSource with select method that depending on public parameter of control. If I set this parameter in markup then all works fine, but if I want to set this parameter dynamicly from code-behind I get an error when do any manipulations with data in gridView of User control.
Jo Asakura
i am at a loss. a bit tired. will revisit tomorrow and see if i have different eyes for it. good luck.
Sky Sanders
A: 

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

Anthony K