页面索引更改目标调用异常

发布于 2024-08-12 08:33:41 字数 752 浏览 3 评论 0原文

我在使用 gridview 整理分页场景时遇到了一些麻烦,即我无法显示页面、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”消息。

作为一个新手,这超出了我目前的能力,并且让我有些困惑。我如何正确绑定我的 gridview 以允许分页正确运行?

I'm having a little bit of trouble sorting out the paging scenario with a gridview i.e. I can't get the bloody thing to show page, 2, 3, 4, etc.

I have the following Grid view code

<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>

With the following

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

Now, I am getting a "TargetinvocationException was unhandled by user code."

Being a newbie, this is beyond my current capabilities and has confused me somewhat. How do I go about binding my gridview properly to allow for the paging to be operate correctly?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

逐鹿 2024-08-19 08:33:41

这就是事情变得有趣的地方!我正在使用 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();
    }

我怀疑我有太多的束缚......正如你可以从我的代码中看出的那样,这对我来说是新领域,所以对虐待要温和!

this is where things get interesting! I am using a linq data source:

<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 being generated through this:

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();
    }

I suspect I have one too many binds kicking about...as you can probalby tell from my code, this is new territory for me so be gentle with the abuse!

花开雨落又逢春i 2024-08-19 08:33:41

好的,我已经阅读了一些需要放入数据源的地方,所以我现在得到了以下代码

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

现在,当我构建页面时,它工作正常,但是当我点击 x 的第 2 页时,我收到了这个令人讨厌的信息小消息:

“/onlineReportingFUNCTIONING”应用程序中的服务器错误。

此提供程序仅在返回包含所有标识列的实体或投影的有序查询上支持 Skip(),其中查询是单表(非联接)查询,或者是 Distinct、Except、Intersect 或 Union(不是 Concat)手术。

那又是什么事?!

Ok, I've read a few places that I need to thrown in the data source so I have now got the following code

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

Now when I build the page, it works fine, but when I hit page 2 of x, I receive this nasty little message:

Server Error in '/onlineReportingFUNCTIONING' Application.

This provider supports Skip() only over ordered queries returning entities or projections that contain all identity columns, where the query is a single-table (non-join) query, or is a Distinct, Except, Intersect, or Union (not Concat) operation.

What's that about then?!

几味少女 2024-08-19 08:33:41

绑定实际上很好。这最终是通过添加主键(我真的应该首先实现的!)进行排序的。

因此,如果有人正在阅读本文,无法让他们的网格视图通过对象数据源进行分页,请确保您有一个主键!

The binding was actually fine. This was finally sorted by adding in a primary key (which I really should have implmented in the first place!)

So if anyone is reading this, cannot get their gridview to page through an objectdatasource, make sure you have a primary key!!!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文