0

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))       
    }
}
4

2 に答える 2

0

こんにちはジョンク私は同じ問題を抱えていて、ついに先週の金曜日の深夜に犯人を割ることができました。この問題は私に悪夢を与えていました、そして私はそれを修正してうれしいです。解決策は簡単です。

私のカウント方法はデータを取得することでした。しかし、いくつかのデータ型の不一致があるようです。カウントを。としてハードコーディングした場合。

return 16

動作しますが、int変数にバインドして変数を返すと、動作しません。16としてハードコーディングする場合、それはstruct system.Int32データ型ですが、int変数を返す場合、それは単なるInt32変数です。問題はここにあると思います。

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

それから幸運にも長い検索の後、私はこの解決策をどこかで見つけました。countメソッドのreturnタイプをstaticintに変更しました

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

データ型にいくつかの不一致があります。今はそよ風のように動作します

于 2010-05-10T12:09:30.913 に答える
0

暗闇の中で突っ込む: StartRowIndex DefaultValue を 1 に設定するとどうなるか?

<asp:Parameter Name="StartRowIndex" Type="Int32" DefaultValue="1" />
<asp:Parameter Name="MaximumRows" Type="Int32" DefaultValue="10" />
于 2010-03-01T17:04:12.940 に答える