我想使用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))
}
}
你在頁面的代碼隱藏中做了什麼,在黑暗中拍攝了什麼,你是否禁用了視圖狀態。 – RubbleFord 2010-02-22 14:56:42
嗨!我在上面添加了代碼...沒有什麼。 – JohnCC 2010-03-01 16:51:27