页面索引更改目标调用异常
我在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这就是事情变得有趣的地方!我正在使用 linq 数据源:
通过以下方式生成 lqPackWeights:
protected void btSearch_Click(object sender, EventArgs e)
{
我怀疑我有太多的束缚......正如你可以从我的代码中看出的那样,这对我来说是新领域,所以对虐待要温和!
this is where things get interesting! I am using a linq data source:
lqPackWeights being generated through this:
protected void btSearch_Click(object sender, EventArgs e)
{
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!
好的,我已经阅读了一些需要放入数据源的地方,所以我现在得到了以下代码
现在,当我构建页面时,它工作正常,但是当我点击 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
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?!
绑定实际上很好。这最终是通过添加主键(我真的应该首先实现的!)进行排序的。
因此,如果有人正在阅读本文,无法让他们的网格视图通过对象数据源进行分页,请确保您有一个主键!
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!!!