修改从 ObjectDataSource 返回的集合

发布于 2024-10-09 00:08:05 字数 616 浏览 0 评论 0原文

关于我正在处理的内容的一些快速背景知识:

  • 我有一个页面,其中 RadGrid 绑定到 ObjectDataSource,该 ObjectDataSource 返回
  • 该页面上的对象集合;我还有两个清单;一个包含需要与从 ObjectDataSource 返回的集合合并的对象的 ID,另一个包含需要从该集合中删除的对象的 ID。
  • 当前处理此问题的过程非常黑客;当一个项目添加到这两个列表之一时;调用一个单独的方法,将 myDataSource.Select() 的结果转储到变量中,并执行操作。然后,网格的 DataSourceId 被清除,集合被分配给 DataSource 属性,然后调用 DataBind。 (本质上是解开 ObjectDataSource 并使用手动数据绑定)

我的问题如下:是否可以以某种方式“拦截”从 ObjectDataSource 返回的集合,以便我可以在将集合传递到 RadGrid 之前对其进行操作?

如果这不可能;这不是一个破坏交易的事情。我相信我可以修改 Select() 方法以接受两个列表;并在那里执行操作。我的另一个途径是为网格实现 NeedDataSource() 事件,并在那里进行操作。

理想情况下,我想使用第一个选项。以前有人成功做到过吗?

Some quick background on what I'm working on:

  • I've got a page with a RadGrid tied to an ObjectDataSource that returns a collection of objects
  • On that page; I also have two lists; one contains Ids of objects that need to merged with the collection returned from the ObjectDataSource, and the other contains Ids of objects that need to be removed from that collection
  • The current process for handling this is very hack-ish; when an item is added to either one of those two lists; a separate method is called which dumps the results of myDataSource.Select() into a variable, and performs the manipulation. The grid then has its DataSourceId cleared, and the collection is assigned to the DataSource property, and then DataBind is called. (essentially untying the ObjectDataSource and using manual databinding instead)

My question is as follows: Is it possible to somehow "intercept" the collection returned from the ObjectDataSource so I can manipulate the collection before it is passed to the RadGrid?

If this isn't possible; it's not a dealbreaker. I believe I can modify the Select() method to accept the two lists; and perform the manipulation there. Another avenue I have is to implement the NeedDataSource() event for the grid, and manipulate there as well.

Ideally, I'd like to use the first option. Has anybody been successful doing this before?

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

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

发布评论

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

评论(1

浮世清欢 2024-10-16 00:08:05

您可以从 ObjectDataSource & 派生; ObjectDataSourceView,并分别重写GetView &执行选择,类似这样:

public class MyObjectDataSource : ObjectDataSource
{
    private MyObjectDataSourceView _view;
    private MyObjectDataSourceView GetView()
    {
        if (_view == null)
        {
            _view = new MyObjectDataSourceView(this, "DefaultView", Context);
            if (IsTrackingViewState)
            {
                ((IStateManager)_view).TrackViewState();
            }
        }
        return _view;
    }

    protected override DataSourceView GetView(string viewName)
    {
        return GetView();
    }
}

public class MyObjectDataSourceView : ObjectDataSourceView
{
    public MyObjectDataSourceView(MyObjectDataSource owner, string name, HttpContext context)
        : base(owner, name, context)
    {
    }

    protected override IEnumerable ExecuteSelect(DataSourceSelectArguments arguments)
    {
        IEnumerable dataSource = base.ExecuteSelect(arguments);
        // TODO: do your stuff here
        return dataSource;
    }
}

You can derive from ObjectDataSource & ObjectDataSourceView, and respectively override GetView & ExecuteSelect, something like this:

public class MyObjectDataSource : ObjectDataSource
{
    private MyObjectDataSourceView _view;
    private MyObjectDataSourceView GetView()
    {
        if (_view == null)
        {
            _view = new MyObjectDataSourceView(this, "DefaultView", Context);
            if (IsTrackingViewState)
            {
                ((IStateManager)_view).TrackViewState();
            }
        }
        return _view;
    }

    protected override DataSourceView GetView(string viewName)
    {
        return GetView();
    }
}

public class MyObjectDataSourceView : ObjectDataSourceView
{
    public MyObjectDataSourceView(MyObjectDataSource owner, string name, HttpContext context)
        : base(owner, name, context)
    {
    }

    protected override IEnumerable ExecuteSelect(DataSourceSelectArguments arguments)
    {
        IEnumerable dataSource = base.ExecuteSelect(arguments);
        // TODO: do your stuff here
        return dataSource;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文