对象数据源 ->未指定 SelectMethod

发布于 2024-08-22 05:39:55 字数 1722 浏览 2 评论 0原文

我使用 ObjectDataSource + ASPxGridView 创建了一个 UserControl。 ObjectDataSource 的 SelectMethod 我根据 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());
    }
}

当我在页面上使用我的控件时,如下所示:

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

或将其放入另一个 ASPxGridView 中,如下所示:

<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>

一切正常,但我想从代码隐藏中声明 Control 参数

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

然后在 Page_Load 上声明:

personsManager.CompanyID = 2;

如果我使用之前的声明,那么我只能看到 UserControl 的 ASPxGridView 的第一次加载以及一些数据,因为任何操作都会导致 UserControl 的 ASPxGridView 的 HtmlRowCreated 事件出错:

不支持选择操作 通过 ObjectDataSource 'dsPersons' 除非 指定了 SelectMethod。

为什么会发生这种情况?

谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

渡你暖光 2024-08-29 05:39:55

添加对象数据源时,将出现一个向导,让您在对象上选择支持数据库的典型 CRUD 方法的方法。

单击 objectDataSource 的智能标签并选择“配置数据源”,您将看到。

然后看看 http://msdn.microsoft.com/en-us /library/9a4kyhcx.aspx 学习如何实现这些方法..

祝你好运。

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.

奢欲 2024-08-29 05:39:55

看看这篇博客文章 “手动设置 ObjectDataSource.SelectMethod 属性 BUG”,作者:Eran Nachum。他描述了如何在 OnInit 事件期间设置网格的数据源,然后在 OnPreRender 期间进行数据绑定。

(上面引用的网站不再活跃。回程机器上有博客文章的副本:Eran Nachum 2007 年 12 月在 Wayback Machine 上的博客

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文