0

我想使用ObjectDataSource分頁將自定義分頁添加到我的網站。我相信我已經正確地添加了我需要的存儲過程,並通過DAL和BLL提供了它們。我遇到的問題是,當我嘗試在頁面上使用它時,我得到一個空的數據網格。在ASP.NET中自定義分頁的問題

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PageTest.aspx.cs" Inherits="developer_PageTest" %> 

<!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"> 
    <div> 
     <asp:ObjectDataSource ID="ObjectDataSource1" SelectMethod="GetMessagesPaged" EnablePaging="true" 
      SelectCountMethod="GetMessagesCount" TypeName="MessageTable" runat="server" > 
      <SelectParameters> 
       <asp:Parameter Name="DeviceID" Type="Int32" DefaultValue="112" /> 
       <asp:Parameter Name="StartDate" Type="DateTime" DefaultValue="" ConvertEmptyStringToNull="true"/> 
       <asp:Parameter Name="EndDate" Type="DateTime" DefaultValue="" ConvertEmptyStringToNull="true"/> 
       <asp:Parameter Name="BasicMatch" Type="Boolean" ConvertEmptyStringToNull="true" DefaultValue="" /> 
       <asp:Parameter Name="ContainsPosition" Type="Boolean" ConvertEmptyStringToNull="true" DefaultValue="" /> 
       <asp:Parameter Name="Decoded" Type="Boolean" ConvertEmptyStringToNull="true" DefaultValue="" /> 
<%--    <asp:Parameter Name="StartRowIndex" Type="Int32" DefaultValue="10" /> 
       <asp:Parameter Name="MaximumRows" Type="Int32" DefaultValue="10" /> 
--%>   </SelectParameters>  
     </asp:ObjectDataSource>   

     <asp:GridView ID="GridView1" runat="server" DataSourceID="ObjectDataSource1" AllowPaging="true" PageSize="10"></asp:GridView> 
     <br /> 

     <asp:Label runat="server" ID="lblCount"></asp:Label> 

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

當我設置EnablePaging假的消耗臭氧層物質,並在標記添加註釋StartRowIndex和MaximumRows PARAMS,我得到的數據,以便它真的好像理所應當的數據層行爲。代碼文件中的代碼將GetMessagesCount調用的值放入lblCount中,並且它總是有一個合理的值。我已經試過在BLL中破解並且逐步完成,並且後端正在調用,並且它正在返回看起來像正確的信息和數據,但是在ODS和GridView之間消失。

我創建了一個模擬數據源,它返回了隨機數字的編號行,並將它附加到這個表單上,並且自定義分頁工作,所以我認爲我對這種技術的理解很好。我只是不明白爲什麼它在這裏失敗!

任何幫助真的很感激。

(編輯..這是後面的代碼)。如果設置了默認值StartRowIndex 1會發生什麼:在黑暗中

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.ComponentModel; 

public partial class developer_PageTest : System.Web.UI.Page 
{ 
    protected void Page_Load(object sender, EventArgs e) 
    { 
     lblCount.Text = String.Format("Count = {0}", MessageTable.GetMessagesCount(112, null, null, null, null, null))  
    } 
} 
+0

你在頁面的代碼隱藏中做了什麼,在黑暗中拍攝了什麼,你是否禁用了視圖狀態。 – RubbleFord 2010-02-22 14:56:42

+0

嗨!我在上面添加了代碼...沒有什麼。 – JohnCC 2010-03-01 16:51:27

回答

0

野生刺?

<asp:Parameter Name="StartRowIndex" Type="Int32" DefaultValue="1" /> 
<asp:Parameter Name="MaximumRows" Type="Int32" DefaultValue="10" /> 
+0

Hi Luhmann。這些參數僅用於調試。當啓用分頁時,ObjectDataSource會自動將這些分頁提供給BLL。如果我禁用了分頁並且只想測試標準的數據綁定,那麼我必須將它們放入,以便調用正確的方法。如果我將StartRowIndex設置爲1,我會得到前10行,如預期的那樣!但只有當EnabledPaging =「false」時。 – JohnCC 2010-03-02 11:22:38

0

嗨Johncc我有同樣的問題,終於能夠在上午5點在午夜破解罪魁禍首。天哪男人這個問題給了我噩夢,我很高興我修好了它。解決方案很簡單。

我的計數方法正在追蹤數據。但似乎有一些數據類型不匹配。如果我將計數硬編碼爲。

return 16

它會工作,但如果我把它綁定到一個int變量,並返回變量它wouldnt工作。 如果你的硬編碼爲16,它是一個struct system.Int32數據類型,但是如果你返回一個int變量,它只是一個Int32變量。我認爲問題在於此。

public int GetsrchCount(BeginDate,EndDate) 
{ 
    int intrec; 
    intrec = 23; 
    return intrec; 
} 

然後經過漫長的搜索幸運地,我發現這個解決方案有些地方。我將計數方法的返回類型更改爲static int

public static int GetsrchCount(DateTime BeginDate, DateTime EndDate) 
    { 
     int intrec; 
     intrec = 23; 
     return intrec; 
    } 

數據類型存在一些不匹配。它現在就像一陣微風