记录计数与SQL数据源和放大器asp.net gridview的;分页 [英] Records count in asp.net gridview with SQL data source & Paging
本文介绍了记录计数与SQL数据源和放大器asp.net gridview的;分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要数到在asp.net gridview的SQL查询返回的记录总数,而我使用分页显示只有20页的记录。
所以,当我用这个code将其返回只有20行(因为分页的。)
INT totalrow = Convert.ToInt32(GridView1.Rows.Count);
我如何能指望从网格视图总数或记录?
< ASP:SqlDataSource的ID =SqlDataSource1DataSourceMode =数据集EnableCaching =真CacheDuration =1800
=服务器的ConnectionString =<%$的ConnectionStrings:DatabaseConnectionString1%>中
的ProviderName =下;%$的ConnectionStrings:DatabaseConnectionString1.ProviderName%>中
的SelectCommand =SELECT * FROM表
解决方案
您可以在页面加载做到这一点。
保护无效的Page_Load(对象发件人,EventArgs的发送)
{
诠释计数;
System.Data.DataView DV =(数据视图)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
数= dv.Count;
}
或者你也可以做到这一点。
保护无效SqlDataSource1_Selected(对象发件人,SqlDataSourceStatusEventArgs E)
{
诠释计数;
数= e.AffectedRows;
}
I want to count to total number of records returned with a SQL query in asp.net gridview, while i am using paging to display only 20 records in a page. So when i use this code it return only 20 rows(Because of paging.)
int totalrow = Convert.ToInt32(GridView1.Rows.Count);
How can i count the total number or records from Grid view?
<asp:SqlDataSource ID="SqlDataSource1" DataSourceMode="DataSet" EnableCaching="true" CacheDuration="1800"
runat="server" ConnectionString="<%$ ConnectionStrings:DatabaseConnectionString1 %>"
ProviderName="<%$ ConnectionStrings:DatabaseConnectionString1.ProviderName %>"
SelectCommand="Select * from Table"
解决方案
You can do this on Page Load
protected void Page_Load(object sender, EventArgs e)
{
int count;
System.Data.DataView dv = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
count = dv.Count;
}
or you can also do this
protected void SqlDataSource1_Selected(object sender, SqlDataSourceStatusEventArgs e)
{
int count;
count = e.AffectedRows;
}
这篇关于记录计数与SQL数据源和放大器asp.net gridview的;分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文