【问题标题】:How do I convert a DataView to an ObjectDataSource如何将 DataView 转换为 ObjectDataSource
【发布时间】:2013-12-13 23:44:33
【问题描述】:

我目前正在将 SPGridView 绑定到 DataView。我想绑定到 ObjectDataSource,而不是使用 SPGridView 的 .DataSourceID 属性,这样我就可以在我的网格上进行过滤,这不适用于 DataView(从我读过的内容)。有没有一种简单的方法可以从 DataView 实例化 ObjectDataSource?我发现了一些相关的问题,但没有一个答案显示足够的代码上下文来让我弄清楚如何做到这一点。

这是我的代码现在的样子以及我想要做什么:

DataSet myDataSet;
myDataSet = populateDataFromDatabaseBasedOnSomeSearchParameters(startDate, endDate);
DataView myGridDataView = myDataSet.Tables[0];

// Somewhere in here convert to an ObjectDataSource so that I can bind using DataSourceID instead and get filtering to work

SPGridView myGridView;
myGridView.DataSource = myGridView;

myGridView.DataBind();

【问题讨论】:

    标签: asp.net data-binding sharepoint-2010


    【解决方案1】:

    我不知道在 C# 中将 DataView 转换为 ObjectDataSource 的任何方法。 但是,您可以为 DataView 和 GridView 使用相同的 DataSource。

    myDataSource.DataSource = someDataSource;
    myGridView.DataSource = someDataSource;
    myDataSource.DataBind();
    myGridView.DataBind();
    

    然后,当您的 DataView 更改时,更新 DataSource 并重新绑定您的 GridView。

    private void myDataView_OnListChanged(object sender, 
        System.ComponentModel.ListChangedEventArgs args)
    {
        //Update the DataSource someDataSource
        myGridView.DataBind();
    }
    

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 2014-10-08
      • 1970-01-01
      • 2010-12-06
      • 2012-03-16
      • 2011-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-30
      相关资源
      最近更新 更多