0

グリッドビューを使用してページング シナリオを整理するのに少し問題があります。つまり、血まみれのページ、2、3、4 などを表示することができません。

次のグリッドビューコードがあります

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
               style="z-index: 1; left: 20px; top: 440px; position: absolute; height: 133px; " 
        AllowPaging="True" AllowSorting="True" Font-Size="Small" 

        PageSize="2" onpageindexchanging="GridView1_PageIndexChanging">
        <Columns>

以下で

  protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    GridView1.PageIndex = e.NewPageIndex;
    GridView1.DataBind();
}

現在、「TargetinvocationException was unhandled by user code.」というメッセージが表示されています。

初心者なので、これは私の現在の能力を超えており、多少混乱しています。ページングが正しく動作するように、グリッドビューを適切にバインドするにはどうすればよいですか?

4

3 に答える 3

0

これは物事が面白くなるところです!linqデータソースを使用しています:

<asp:LinqDataSource ID="**lqPackWeights**" runat="server"
        ContextTypeName="ORWeightsDataClassesDataContext" 
        Select="new (UnitId, UnitDescription, PackagingTypeCode, UnitWeight, WeightUnitCode, RecycledContent, IsBiodegradable, Recyclability, RevisionSourceCode, RevisionDate, ExtendedMaterialName, MaterialText, WeightStatus, ProductPercentage, UnitUserfield1, UnitUserfield2, IDDesc, MaterialLevel)" 
        TableName="tblOnlineReportingCOMPLETEWeights" Where="IDDesc == @IDDesc">
    </asp:LinqDataSource>

これによって生成されるlqPackWeights:

private object GetMaterialData(string MemberKey, string MaterialType, string MaterialLevel, int Count)
{
    ORWeightsDataClassesDataContext db = new ORWeightsDataClassesDataContext();
    var query = db.tblOnlineReportingCOMPLETEWeights
                .Where(x => x.MaterialLevel == MaterialLevel && x.MaterialText == MaterialType && x.MemberId == MemberKey)
                .OrderByDescending(x => x.ProductPercentage).Take(Count);
    return query;
}

protected void btSearch_Click(object sender、EventArgs e){

    lqPackWeights.WhereParameters.Clear();
    ControlParameter cp = new ControlParameter();
    cp.Type = TypeCode.String;


    if (radBuyer.Checked)
    {
        cp.ControlID = "ddlProd";
        cp.PropertyName = "SelectedValue";
        cp.Name = "IDDesc";
        lqPackWeights.WhereParameters.Add(cp);
        GridView1.DataSourceID = "lqPackWeights";
        GridView1.DataBind();
    }

    else if (radProd.Checked)
    {
        cp.ControlID = "tbxProdAC";
        cp.PropertyName = "Text";
        cp.Name = "IDDesc";
        lqPackWeights.WhereParameters.Add(cp);
        GridView1.DataSourceID = "lqPackWeights";
        GridView1.DataBind();
    }

バインドが多すぎるのではないかと思います...私のコードからprobalbyがわかるように、これは私にとって新しい領域なので、悪用に優しくしてください!

于 2009-11-26T16:47:15.397 に答える
0

わかりました。データ ソースにスローする必要があるいくつかの場所を読んだので、次のコードを取得しました。

 protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    GridView1.PageIndex = e.NewPageIndex;
    GridView1.DataSourceID = "lqPackWeights";
}

ページを作成すると問題なく動作しますが、x ページの 2 ページ目に到達すると、次の厄介な小さなメッセージが表示されます。

「/onlineReportingFUNCTIONING」アプリケーションでサーバー エラーが発生しました。

このプロバイダーは、クエリが単一テーブル (非結合) クエリであるか、Distinct、Except、Intersect、または Union (Concat ではない) である場合に、すべての ID 列を含むエンティティまたはプロジェクションを返す順序付きクエリに対してのみ Skip() をサポートします。手術。

じゃあ何の話だ!?

于 2009-11-26T17:22:59.257 に答える