2011-02-02 21 views
1
System.NotSupportedException was unhandled by user code 
    Message=The data source does not support sorting. 
    Source=namespace 
    StackTrace: 
     at namespace.Admin.ToolkitScriptManager1_AsyncPostBackError(Object sender, AsyncPostBackErrorEventArgs e) in C:\project\Master.cs:line 27 
     at System.Web.UI.ScriptManager.OnAsyncPostBackError(AsyncPostBackErrorEventArgs e) 
     at System.Web.UI.PageRequestManager.OnPageError(Object sender, EventArgs e) 
     at System.Web.UI.TemplateControl.OnError(EventArgs e) 
     at System.Web.UI.Page.HandleError(Exception e) 
     at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 
     at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 
    InnerException: 



    protected void ToolkitScriptManager1_AsyncPostBackError(object sender, AsyncPostBackErrorEventArgs e) 
     { 
      ToolkitScriptManager1.AsyncPostBackErrorMessage = Resources.Strings.ErrorAsyncPostBack; 
      logger.Error("An asyncpostbackerror has occurred: " + e.Exception.Message); 
      throw e.Exception; // <<<<<< throw error here 
     } 


    <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
     DataObjectTypeName="mynamespace.Product" SelectMethod="GetAllProducts" SortParameterName="sortedBy" 
      TypeName="mynamespace.Products" UpdateMethod="Update">    
      <SelectParameters> 
       <asp:Parameter Name="sortedBy" DefaultValue="DisplayOrdinal, Name" /> 
      </SelectParameters> 
      </asp:ObjectDataSource> 
下面

使用简单的GridView我的代码,我只具有排序问题和分页按预期工作,我甚至定义ONSorting事件,但它仍然抛出我的错误:The data source does not support sorting.配置ObjectDataSource控件进行排序

namespace mynamespace 
{ 
public class Product 
{ 
private int _id; 

public int Id 
{ 
get { return _id; } 
set { _id = value; } 
} 
private string _code; 

public string Code 
{ 
get { return _code; } 
set { _code = value; } 
} 
private string _name; 

public string Name 
{ 
get { return _name; } 
set { _name = value; } 
} 


<asp:GridView ID="GridView1" runat="server" DataKeyNames="Id" 
AutoGenerateColumns="False" OnSorting="gridview1_Sorting" DataSourceID="ObjectDataSource1" > 
<Columns> 
<asp:CommandField ShowEditButton="True" /> 
<asp:BoundField DataField="Id" HeaderText="Id" 
SortExpression="Id" ReadOnly="True" /> 
<asp:BoundField DataField="Code" HeaderText="Code" 
SortExpression="Code" /> 
<asp:BoundField DataField="Name" HeaderText="Name" 
SortExpression="Name" /> 
<asp:TemplateField HeaderText="State/Province" SortExpression="StateProvinceName" 
        HeaderStyle-Wrap="true" HeaderStyle-Width="80px"> 
        <ItemTemplate> 
         <%# ((namespace)(Container.DataItem)).StateProvince.Name.ToString()%> 
        </ItemTemplate> 
        <EditItemTemplate> 
         <asp:DropDownList ID="ddlState" runat="server" DataSourceID="StateDataSource" DataTextField="Name" 
          DataValueField="StateProvinceId" AutoPostBack="false"> 
         </asp:DropDownList> 
        </EditItemTemplate> 
       </asp:TemplateField> 

</Columns> 
</asp:GridView> 

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
DataObjectTypeName="mynamespace.Product" 
SelectMethod="GetAllProducts" TypeName="mynamespace.Products" 
UpdateMethod="Update"> 
</asp:ObjectDataSource> 




protected void gridview1_Sorting(object sender, GridViewSortEventArgs e) 
     { 
      if (e.SortExpression == SortField) 
      { 
       if (SortDirection != null) 
       { 
        if (SortDirection == "ASC") 
         SortDirection = "DESC"; 
        else 
         SortDirection = "ASC"; 
       } 
       else 
       { 
        if (e.SortDirection == System.Web.UI.WebControls.SortDirection.Ascending) 
         SortDirection = "ASC"; 
        else 
         SortDirection = "DESC"; 
       } 
      } 
      else 
      { 
       if (e.SortDirection == System.Web.UI.WebControls.SortDirection.Ascending) 
        SortDirection = "ASC"; 
       else 
        SortDirection = "DESC"; 
      } 
      SortField = e.SortExpression; 
      DataBind(); 
     } 


    protected override void Page_Load(object sender, EventArgs e) 
     { 
      GridView1.DataSourceID = "ObjectDataSource1"; 

     } 


protected void somecustomlinks_ItemCommand(object source, EventArgs e) 
     { 
      DataBind(); 
     } 

public override void DataBind() 
{ 
    List<Organization> _org = new List<Organization>(); 
    Gridview1.DataSourceID = string.Empty; 
    Gridview1.DataSource = _orgFilter; 
    Gridview1.DataBind(); 

} 

回答

0

为了支持与ObjectDataSource排序,业务对象的Select方法(GetAllProducts()你的情况)应该采取包含排序表达式以应用参数。

您还必须将ObjectDataSourceSortParameterName属性设置为该参数的名称。

+0

Fred:我更新了我的问题,我确实有这些行,但不知何故,我错过了粘贴我的代码时,pelase看到我的问题。 – 2011-02-02 14:52:04

相关问题