我在使用 Paging 和 LinqDataSource 作为数据源获取 Gridview 中显示的项目的总行数时遇到问题。
我尝试了几种方法:
protected void GridDataSource_Selected(object sender, LinqDataSourceStatusEventArgs e)
{
totalLabel.Text = e.TotalRowCount.ToString();
}
每次都返回-1。
protected void LinqDataSource1_Selected(object sender, LinqDataSourceStatusEventArgs e)
{
System.Collections.Generic.List<country> lst = e.Result as System.Collections.Generic.List<country>;
int count = lst.Count;
}
只给我当前页面的计数,而不是总数。
还有什么建议吗?
最佳答案
这些事件中返回的 LinqDataSourceEventArgs 在这些情况下返回 -1:
-1 if the LinqDataSourceStatusEventArgs object was created during a data modification operation; -1 if you enabled customized paging by setting AutoPage to true and by setting RetrieveTotalRowCount to false.
Check here for more information - 靠近底部的表格显示了要设置的不同属性以获取行数,但看起来您必须将 AutoPage 和 AllowPage 属性设置为 true 或都为 false。
根据上面链接中的表格和您提供的示例,您将 Autopage 设置为 false,但将 AllowPaging 设置为 true,因此它返回页面中的行数。
HTH
关于c# - 使用 LinqDataSource 和分页的 GridView 控件中的总行数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27711/