整个网格视图中的总行数 [英] total number of rows in an entire gridview

查看:119
本文介绍了整个网格视图中的总行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要获取返回到GridView的项目/记录总数。

如果我只是做myGridView.Rows.Count,那么它只返回我的总数
$ b页面上的$ b项目。

但如果我有,10页(每页10条记录)和98条记录,

Rows.Count将返回10最后一页上的前9页和8页。

但是,我需要以某种方式访问​​总记录数为98.什么

是正确的/简单的方法来实现它?

I need to get the total number of items/records returned into GridView.
If I just do myGridView.Rows.Count, then it just returns me the total number
of items on the page.
But if I have, 10 pages (10 records per page) and 98 records total,
Rows.Count will return me 10 on the first 9 pages, and 8, on the last page.
But, I need to somehow get access to total record count which is 98. What
is the proper/easy way to accomplish that?

推荐答案

如果你提到你是否在为网格视图使用SQLDataSource或ObjectDataSource,那将会很有帮助



如果是ObjectDataSource,

处理所选事件。 ObjectDataSourceStatusEventArgs的成员'ReturnType'将拥有您可以从中获取数据的数据源

例如:

It'd be helpful if you mentioned if you're using an SQLDataSource or an ObjectDataSource for your grid view

If ObjectDataSource,
Handle the selected event. The ObjectDataSourceStatusEventArgs 's member 'ReturnType' will have your data source from which you can get the count
Eg:
int RecordsCount = ((DataSet)e.ReturnValue).Tables[0].Rows.Count;



或者ReturnValue甚至可以是DataView。你最好检查一下。



如果使用SqlDataSource,

处理选定的事件

SqlDataSourceStatusEventArgs的成员'AffectedRows'将有计数

例如:


Or the ReturnValue could even be a DataView. It's better you check.

If using an SqlDataSource,
Handle the selected Event
The SqlDataSourceStatusEventArgs's member 'AffectedRows' will have the count
Eg:

SqlDataSource1_Selected(Object sender, 
System.Web.UI.WebControls.SqlDataSourceStatusEventArgs e)
{
   e.AffectedRows 
...


Hi
You将数据源分配给网格时需要设置总记录。



例如

Hi You need to Set Total Records when you assign DataSource to the Grid.

e.g.
int TotalRecord = dt.Rows.Count(); //This is total number of records in gridview
GridView1.DataSource = dt;
GridView1.DataBind();







谢谢,

Imdadhusen




Thanks,
Imdadhusen


您好,

获得总计数的简便方法是。



1首先获取gridView DataSource。例如



你绑定了一个DataSet然后从GridView获取DataSet格式。



喜欢

DataSet DS =(DataSet)MygridView.DataSource;





2.然后计算编号。在它的行。



喜欢

int count = DS.Tables [0] .Rows.Count;



我希望这能解决你的问题。



以下方法将返回行的总数。



private int GetTotalRow()

{

int Rowcount = 0;

try

{

DataSet DS =(DataSet)MygridView.DataSource;

Rowcount = DS.Tables [0] .Rows.Count;

}

catch

{

throw;

}

返回Rowcount;

}



谢谢
Hi,
The easy way to get the Total count is.

1. First get the gridView DataSource. e.g

you have bind a DataSet then get the DataSet form the GridView.

like
DataSet DS = (DataSet) MygridView.DataSource;


2.Then count the no. of row in it.

like
int count = DS.Tables[0].Rows.Count;

I hope this will solve your problem.

Below is method that will return the Total number of Row.

private int GetTotalRow()
{
int Rowcount = 0;
try
{
DataSet DS = (DataSet) MygridView.DataSource;
Rowcount = DS.Tables[0].Rows.Count;
}
catch
{
throw;
}
return Rowcount ;
}

Thanks


这篇关于整个网格视图中的总行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆