【问题标题】:ObjectDataSource 's' could not find a non-generic method GetAllUsersObjectDataSource 's' 找不到非泛型方法 GetAllUsers
【发布时间】:2012-07-12 14:57:43
【问题描述】:

我浏览了网络并找到了很多答案,但都没有帮助我解决这个问题!

我在数据项目中有一个方法。然后我有一个带有显示元素的项目。

代码隐藏:

public static DataTable GetAllobjs(SPWeb objWeb)
{
    DataTable tmpData = new DataTable();
    try
    {
        allProjects.Columns.Add(ColumnNames.1);
        allProjects.Columns.Add(ColumnNames.2);
        allProjects.Columns.Add(ColumnNames.3);
        allProjects.Columns.Add(ColumnNames.4);
        allProjects.Columns.Add(ColumnNames.5);
        allProjects.Columns.Add(ColumnNames.6);
        allProjects.Columns.Add(ColumnNames.7);
        allProjects.Columns.Add(ColumnNames.8);
        allProjects.Columns.Add(ColumnNames.9);

        //Get the raw project data 
        List<obj> data= DataAquisition.GetAllobj(objWeb);

        /// Loop through the raw data.
        foreach (obj currentInformation in data)
        {
            // Creates a new data row containing information required and adds it to the DATAtable
        }
    }
    catch (Exception exc)
    {
        // Logs errors here
    }
    return tmpData;
}

在用户控件的后面(cs)页面中,我有一个调用 GetAllobjs(SPWeb objWeb)的方法

[DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
public DataTable GetAllUsers()
{
    return Data.GetAllobjs(SPContext.Current.Web);
}

然后页面加载:

ObjectDataSource d = new ObjectDataSource();
d.ID = "s";
d.SelectMethod = "GetAllUsers";
d.TypeName = SPGridView.GetType().AssemblyQualifiedName;
this.Controls.Add(d);
/// Apply a data source to the SPGrid View
SPGridView.DataSourceID = d.ID;

然后在创建子控件上创建我的字段并将其绑定到 SPGridview 并调用数据绑定。

我认为这会起作用,但我得到了错误。我不确定我是否在某个地方遗漏了一些组件模型 [] 标签,我希望有人能指出我哪里出错了。

【问题讨论】:

    标签: c# asp.net sharepoint sharepoint-2010 objectdatasource


    【解决方案1】:

    变化:

    d.TypeName = SPGridView.GetType().AssemblyQualifiedName;
    

    到:

     d.TypeName = this.GetType().AssemblyQualifiedName;
    

    示例: 默认.aspx.cs

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    
    namespace Q11454649WebApp
    {
        public partial class _Default : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!this.IsPostBack)
                {
                    ObjectDataSource d = new ObjectDataSource();
                    d.ID = "s";
                    d.SelectMethod = "GetAllUsers";
                    //d.TypeName = SPGridView.GetType().AssemblyQualifiedName;
                    d.TypeName = this.GetType().AssemblyQualifiedName;
                    this.Controls.Add(d);
                    /// Apply a data source to the SPGrid View
                    SPGridView.DataSourceID = d.ID;
                }
            }
    
            [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
            public string[] GetAllUsers()
            {
                return new string[] { "Joe", "Alan", "Michel" };
            }
        }                              
    }
    

    默认.aspx

    <%@ Page Language="C#" AutoEventWireup="true" Codebehind="Default.aspx.cs" Inherits="Q11454649WebApp._Default" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:GridView ID="SPGridView" runat="server" AutoGenerateColumns="False">
                    <Columns>
                        <asp:TemplateField>
                            <ItemTemplate>
                                <asp:Label ID="Label1" runat="server" Text="<%# Container.DataItem %>"></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                </asp:GridView>
            </div>
        </form>
    </body>
    </html>
    

    存档项目:Q11454649WebApp.7z

    【讨论】:

    • aahhhhhgggg 这是一种享受,但每次我排序时,它似乎都会再次添加我的用户控件 grrrrr
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-15
    相关资源
    最近更新 更多