2012-07-12 4 views
1

웹을 살펴본 결과이 중 아무 것도 도움이되지 못했습니다.ObjectDataSource 's'가 비 제너릭 메서드를 찾을 수 없습니다. GetAllUsers

데이터 프로젝트에 메소드가 있습니다. 그런 다음 나는 display 요소가있는 프로젝트를 가지고있다.

코드 숨김 내가 GetAllobjs (SPWeb objWeb) 다음

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

페이지로드를 호출하는 방법을 사용자 컨트롤의 페이지 뒤에 (CS)에서

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; 
} 

:

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를

,536,913 63,210
<%@ 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