求根据条件查询后绑定Gridview,并自定义分页的示例代码??
多条件查询后,将结果绑定到Gridview上,并且自定义Gridview的分页,在分页的时候能够显示正常,而不是点击页数的时候初始化了。
希望是实例代码,能够承受百万级数据
多条件查询后,将结果绑定到Gridview上,并且自定义Gridview的分页,在分页的时候能够显示正常,而不是点击页数的时候初始化了。
希望是实例代码,能够承受百万级数据
解决方案 »
- 关于wap2.0和1.2的选择和区别
- 分页错误,GridView1_RowCommand索引超出范围
- 急得很!FCKeditor编辑器放在win2003服务器在不可用!
- 老师让我用ASP.NET做一个远程售票系统,高手们提供点思路好吗
- DataList 和 DataGrid 的区别?
- 小弟写了一个将MP3批量改名的东东,谁有地方让俺把这个程序挂一下呀!!!
- 高分求得component one 的序列号
- 使用BoundColumn和EditCommandColumn的问题,在线等急!
- 怎样立即删除Cookie所在的文件?
- 大
- 明天准备去图书馆买C#.NET相关的书,各位推荐几本好书吧
- 读取image类型的字段??
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
protected void Page_Load(object sender, EventArgs e)
{
//UART.Common.CheckRoleAndPermission.CheckLogin();
//UART.Common.CheckRoleAndPermission.Check(0, 10);
//第一次加载页面 设置分页控件总数 绑定数据
if (!this.IsPostBack)
{
UART.BLL.Sales.SalesOrderHeader bll = new UART.BLL.Sales.SalesOrderHeader();
this.lblStrWhere.Text = string.Empty;
this.AspNetPager.RecordCount = bll.GetCount(this.lblStrWhere.Text);
this.BindData();
}
}
/// <summary>
/// 绑定订单列表
/// </summary>
private void BindData()
{
UART.BLL.Sales.SalesOrderHeader bll = new UART.BLL.Sales.SalesOrderHeader();
DataSet ds = bll.GetList(this.AspNetPager.PageSize, this.AspNetPager.CurrentPageIndex, this.lblStrWhere.Text, "1");
this.myGridView.DataSource = ds;
this.myGridView.DataBind();
} /// <summary>
/// 分页绑定数据
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void AspNetPager_PageChanged(object sender, EventArgs e)
{
this.BindData();
}/// <summary>
/// Handles the Click event of the btnSearch control.查询相关订单信息
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
protected void btnSearch_Click(object sender, EventArgs e)
{
this.lblStrWhere.Text = "";
//设置查询条件
StringBuilder strWhere = new StringBuilder();
if (this.txtCustomerName.Text.Trim() != "")
{
strWhere.AppendFormat(" and CustomerName like '%{0}%'", UART.Common.PageValidate.InputText(this.txtCustomerName.Text, 50));
}
if (this.txtPhone.Text.Trim() != "")
{
strWhere.AppendFormat(" and Phone like '%{0}%'", UART.Common.PageValidate.InputText(this.txtPhone.Text, 20));
}
if (this.txtCellPhone.Text.Trim() != "")
{
strWhere.AppendFormat(" and CellPhone like '%{0}%'", UART.Common.PageValidate.InputText(this.txtCellPhone.Text, 20));
}
if (this.txtAddress.Text.Trim() != "")
{
strWhere.AppendFormat(" and Address like '%{0}%'", UART.Common.PageValidate.InputText(this.txtAddress.Text, 100));
}
if (strWhere.Length > 0)
{
this.lblStrWhere.Text = strWhere.ToString().Substring(5, strWhere.Length - 5);
}
UART.BLL.Sales.SalesOrderHeader bll = new UART.BLL.Sales.SalesOrderHeader();
this.AspNetPager.RecordCount = bll.GetCount(this.lblStrWhere.Text);
this.BindData();
}
var q=db.Users.Skip(当前页数).Take(当前页数*pageSize)
GO
/****** 对象: StoredProcedure [dbo].[GetRecordFromPage] 脚本日期: 08/14/2010 00:45:30 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/****** Object: Stored Procedure dbo.GetRecordFromPage Script Date: 2008-1-9 9:24:03 ******/-- =============================================
/*
函数名称: GetRecordFromPage
函数功能: 获取指定页的数据
参数说明: @tblName 包含数据的表名
@fldName 关键字段名
@PageSize 每页记录数
@PageIndex 要获取的页码
@OrderType 排序类型, 0 - 升序, 1 - 降序
@strWhere 查询条件 (注意: 不要加 where)
作 者: 铁拳
邮 箱: [email protected]
创建时间: 2004-07-04
修改时间: 2004-07-04
*/
-- =============================================
ALTER PROCEDURE [dbo].[GetRecordFromPage]
@tblName varchar(255), -- 表名
@fldName varchar(255), -- 字段名
@PageSize int = 10, -- 页尺寸
@PageIndex int = 1, -- 页码
@IsReCount bit = 0, -- 返回记录总数, 非 0 值则返回
@OrderType bit = 0, -- 设置排序类型, 非 0 值则降序
@strWhere varchar(2000) = '' -- 查询条件 (注意: 不要加 where)
ASdeclare @strSQL varchar(6000) -- 主语句
declare @strTmp varchar(1000) -- 临时变量
declare @strOrder varchar(500) -- 排序类型if @OrderType != 0
begin
set @strTmp = '<(select min'
set @strOrder = ' order by [' + @fldName + '] desc'
end
else
begin
set @strTmp = '>(select max'
set @strOrder = ' order by [' + @fldName +'] asc'
endset @strSQL = 'select top ' + str(@PageSize) + ' * from ['
+ @tblName + '] where [' + @fldName + ']' + @strTmp + '(['
+ @fldName + ']) from (select top ' + str((@PageIndex-1)*@PageSize) + ' ['
+ @fldName + '] from [' + @tblName + ']' + @strOrder + ') as tblTmp)'
+ @strOrderif @strWhere != ''
set @strSQL = 'select top ' + str(@PageSize) + ' * from ['
+ @tblName + '] where [' + @fldName + ']' + @strTmp + '(['
+ @fldName + ']) from (select top ' + str((@PageIndex-1)*@PageSize) + ' ['
+ @fldName + '] from [' + @tblName + '] where (' + @strWhere + ') '
+ @strOrder + ') as tblTmp) and (' + @strWhere + ') ' + @strOrderif @PageIndex = 1
begin
set @strTmp = ''
if @strWhere != ''
set @strTmp = ' where (' + @strWhere + ')' set @strSQL = 'select top ' + str(@PageSize) + ' * from ['
+ @tblName + ']' + @strTmp + ' ' + @strOrder
endif @IsReCount != 0
set @strSQL = 'select count(*) as Total from [' + @tblName + ']'+' where ' + @strWhereexec (@strSQL)
LINQ+GridView+AspNetPager 实现分页 http://blog.csdn.net/peter521/archive/2008/08/06/2776879.aspx
<asp:LinkButton ID="cmdFirstPage" runat="server" CommandName="Page" CommandArgument="First"
Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex!=0 %>">首页</asp:LinkButton>
<asp:LinkButton ID="cmdPreview" runat="server" CommandArgument="Prev" CommandName="Page"
Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex!=0 %>">前页</asp:LinkButton>
第<asp:Label ID="lblcurPage" ForeColor="Blue" runat="server" Text='<%# ((GridView)Container.Parent.Parent).PageIndex+1 %>'></asp:Label>页/共<asp:Label
ID="lblPageCount" ForeColor="blue" runat="server" Text='<%# ((GridView)Container.Parent.Parent).PageCount %>'></asp:Label>页
<asp:LinkButton ID="cmdNext" runat="server" CommandName="Page" CommandArgument="Next"
Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex!=((GridView)Container.Parent.Parent).PageCount-1 %>">后页</asp:LinkButton>
<asp:LinkButton ID="cmdLastPage" runat="server" CommandArgument="Last" CommandName="Page"
Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex!=((GridView)Container.Parent.Parent).PageCount-1 %>">尾页</asp:LinkButton>
<asp:TextBox ID="txtGoPage" OnTextChanged="txtGoPage_TextChanged" runat="server" Text='<%# ((GridView)Container.Parent.Parent).PageIndex+1 %>'
Width="32px" CssClass="inputmini"></asp:TextBox>页<asp:Button ID="Button3" runat="server"
OnClick="Turn_Click" Text="转到" /></div>
</PagerTemplate>---------------
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
bind();//对GridView进行再次绑定,该函数由自己编写
}
protected void Turn_Click(object sender, EventArgs e)
{ GridView1.PageIndex = int.Parse(((TextBox)GridView1.BottomPagerRow.FindControl("txtGoPage")).Text)-1;
bind();//对GridView进行再次绑定,该函数由自己编写
}
分页存储过程
string sql="";
sql+=条件?"":"and 字段=''";
http://topic.csdn.net/u/20091204/21/722689e1-7824-497c-b709-4b1118264633.html
GridView 实现自定义分页、排序、查询、添加、编辑、多选删除
linq分页用var q=db.Users.Skip(当前页数).Take(当前页数*pageSize)