【问题标题】:ObjectDataSource does not call SelectCount MethodObjectDataSource 不调用 SelectCount 方法
【发布时间】:2011-01-19 21:09:22
【问题描述】:

你能帮我找出问题吗:

我想用分页实现简单的 DataGrid 和 ObjectDataSource 包

我的 .aspx 文件

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._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></title>
</head>
<body>
    <form id="form1" runat="server">


<asp:DataGrid ID="DataGrid1" runat="server"
 DataSourceID="ObjectDataSource1" 
 AllowPaging="true"

 PageSize="2" >
</asp:DataGrid>
<asp:ObjectDataSource
 runat="server"
 ID="ObjectDataSource1"

 TypeName="WebApplication1.AssetComments"

 SelectMethod="SelectMethod2"
 StartRowIndexParameterName="startRowIndex"
 MaximumRowsParameterName="maximumRows"
 SortParameterName="sortParameter"

 SelectCountMethod="GetCount" EnablePaging="True"
/>

    </form>
</body>
</html>

我的 AssetComments 类

namespace WebApplication1
{
 public class AssetComments
 {

  public List<RSSFeed> SelectMethod2(int startRowIndex, int maximumRows, string sortParameter)
  {
   return SelectMethod2().Skip(startRowIndex).Take(maximumRows).ToList();
  }


  public List<RSSFeed> SelectMethod2()
  {
   List<RSSFeed> ret = new List<RSSFeed>(2) { new RSSFeed("11", "1111111"), new RSSFeed("22", "2222222") };

   return ret;
  }


  public int GetCount()
  {
   return 55;
  }
 }


 public class RSSFeed
 {
  public string Title { get; set; }
  public string Description { get; set; }

  public RSSFeed(string title, string description)
  {
   Title = title;
   Description = description;
  }
 }
}

由于某种原因,asp.net 使用 (0,0,"") 参数调用 SelectMethod2 并且不调用 GetCount。

请帮我找出问题

谢谢

【问题讨论】:

    标签: asp.net datagrid objectdatasource


    【解决方案1】:

    您是否尝试过改用 GridView?

    【讨论】:

    • 即使我使用的是gridview,我也面临同样的问题。有什么想法吗?
    • @Florjon,最好使用给您带来问题的相关代码示例开始一个新的、更具体的问题:)
    • @IrishChieftain 你可以看看,stackoverflow.com/questions/8260570/…
    猜你喜欢
    • 2011-01-12
    • 1970-01-01
    • 2013-07-29
    • 1970-01-01
    • 2010-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多