views:

42

answers:

0

I am trying to hook up custom pagination with an ObjectDataSource to my GridView. However, this thing renders no data, but does render the column headers. The debugger clearly indicates a populated DataTable being returned:

<asp:GridView ID="GridView1" runat="server" DataSourceID="ObjectDataSource1" AllowPaging="True" />

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" EnablePaging="True"
  TypeName="CMS.EntityControls.Transfer.TransferDAL"  
  SelectMethod="GetTransfersPaged" 
  MaximumRowsParameterName="maximumRows" 
  StartRowIndexParameterName="startRowIndex" 
  SelectCountMethod="TotalNumberOfTransfers">
</asp:ObjectDataSource>

public static DataTable GetTransfersPaged(int startRowIndex, int maximumRows)
    {
      var sql =
        @"select * from (select @rownum:=@rownum+1 TransferRank, t.* 
from goalcom_Transfer t, (SELECT @rownum:=0) r 
order by Moment) as TransfersWithRowNumbers
where TransferRank > {0} and TransferRank <= {1}";

      sql = string.Format(sql, startRowIndex, startRowIndex + maximumRows);

      var dt = DBHelpers.GetDT(sql, null);
      return dt;
    }

public static long TotalNumberOfTransfers()
    {
      var cachedCount = HttpRuntime.Cache["TotalTransferCount"];
      if (cachedCount != null)
      {
        return Int32.Parse(cachedCount.ToString());
      }
      const string sql = @"select count(*) from goalcom_Transfer";
      var total = DBHelpers.GetScalar(sql, null);
      HttpRuntime.Cache.Add("TotalTransferCount", total, null, DateTime.Now.AddMinutes(1),
                            Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);

      return (long) total;
    }

Thanks, Mark