2012-07-12 47 views
1

我查看了網絡並發現了很多答案,其中沒有一個幫助我解決此問題!ObjectDataSource'''找不到非通用方法GetAllUsers

我在數據項目中有一個方法。然後我有一個顯示元素的項目。

代碼隱藏:

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)的用戶控制I有一個調用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並調用數據綁定。

我認爲這會工作,但我得到的錯誤。我不確定我是否在某處丟失了更多的組件模型標籤,我希望有人能夠指出我出錯的地方。

回答

3

變化:

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

到:

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

實施例: Default.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" }; 
     } 
    }        
} 

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

+0

aahhhhhgggg這個工作的對待每一次我那種似乎再次添加我的用戶控制時間grrrrr – Truezplaya 2012-07-12 15:55:42

相關問題