ObjectDataSource ページングを使用して、サイトにカスタム ページングを追加しようとしています。必要なストアド プロシージャを正しく追加し、DAL と BLL を使用してそれらを作成したと思います。私が抱えている問題は、ページで使用しようとすると、空のデータグリッドが表示されることです。
<%@ 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>
ODS で EnablePaging を false に設定し、コメント アウトされた StartRowIndex および MaximumRows パラメータをマークアップに追加すると、データが取得されるので、データ レイヤーが本来の動作をしているように見えます。コード ファイルには、GetMessagesCount 呼び出しの値を lblCount に入れるためのコードがあり、その中には常に適切な値が含まれています。
私は BLL を壊してステップスルーしようとしましたが、バックエンドが呼び出され、正しい情報とデータのように見えるものを返していますが、ODS と GridView の間で何らかの形で消えています。
乱数の番号付き行を返すモック データ ソースを作成し、このフォームに添付しました。カスタム ページングが機能したので、テクニックの理解は良好だと思います。ここで失敗する理由がわかりません!
どんな助けでも本当に感謝しています。
(編集..コードビハインドです)。
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))
}
}