ObjectDataSource,返回带有两个或更多表的DataSet

时间:2012-05-09 15:22:06

标签: asp.net data-binding dataset objectdatasource

我正在编写自己的ObjectDataSource SelectMethod,如下所示:

public class SomeDataprovider
{
    [DataObjectMethod(DataObjectMethodType.Select)]
    public DataSet GetData()
    {
        NWdbTableAdapters.CustomersTableAdapter a1 = new CustomersTableAdapter();
        NWdbTableAdapters.SuppliersTableAdapter a2 = new SuppliersTableAdapter();

        NWdb.CustomersDataTable dt1 = a1.GetTop10();
        NWdb.SuppliersDataTable dt2 = a2.GetTop10();
        dt1.TableName = "Table1";
        dt2.TableName = "Table2";
        DataSet ds = new DataSet();
        ds.Tables.Add(dt1);
        ds.Tables.Add(dt2);
        return ds;
    }
}

页面中有两个网格视图:

    <asp:GridView ID="GridView1" runat="server" DataSourceID="ObjectDataSource1">
    </asp:GridView>
    <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
        SelectMethod="GetData" TypeName="odsMultipleDataTables.SomeDataprovider">
    </asp:ObjectDataSource>
    <asp:GridView ID="GridView2" runat="server" DataSourceID="ObjectDataSource1">
    </asp:GridView>

我试图让“Table1”出现在GridView1中,“Table2”分别出现在GridView2中。但是当我在网格上设置DataMember属性时,我得到了错误。

Error Screenshot

如何实现我想要的目标?

0 个答案:

没有答案