怎样实现分页
在页面中拖入一个GridView控件,一个button控件,怎样使GridView分页。要代码哦。》 --------------------编程问答-------------------- 前台设置GridView AllowPaging=true 并设置pagesize 默认是10后台写 GridView 分页事件
GridView 72般绝技 --------------------编程问答-------------------- 用分页控件吧,aspnetpager --------------------编程问答-------------------- 最好不要用GridView自带的分页,根本就是一个样子罢了,如果数据有上万行就会影响性能的!
你用分页存储过程分页吧!手动写分页方法,如果不想写就用分页控件吧!网上的分页控件很多! --------------------编程问答-------------------- 用分页控件 --------------------编程问答-------------------- ASP.NET WebForm分页控件AspNetPager:http://www.webdiyer.com/controls/aspnetpager
ASP.NET MVC分页组件MvcPager:http://www.webdiyer.com/controls/mvcpager --------------------编程问答-------------------- 新手还是慢慢来,不要用分页控件,gridview一般就用AllowPaging=true ,那是给repeater和datalist用的,他们不能分页…… --------------------编程问答-------------------- 数据不是很大的话直接设置GridView AllowPaging=true 并设置pagesize 默认是10
--------------------编程问答-------------------- <asp:GridView ID="GridView1" runat="server" PageSize="10" AllowPaging="True"
AllowSorting="True" Width="100%" DataKeyNames="CLID"><PagerSettings Visible="False" />
<!-- 这段配置中 PagerSettings 设置很重要!-->
<Columns>
<asp:BoundField HeaderText="编号" DataField="CLID" HeaderStyle-BackColor="#d3eaef"
ItemStyle-BackColor="#FFFFFF">
<HeaderStyle BackColor="#D3EAEF"></HeaderStyle>
<ItemStyle BackColor="White" HorizontalAlign="Center"></ItemStyle>
</asp:BoundField>
</Columns>
</asp:GridView>
<webdiyer:aspnetpager id="AspNetPager1" runat="server" CustomInfoTextAlign="left" HorizontalAlign="Right" SubmitButtonClass="button" SubmitButtonText="跳转" CenterCurrentPageButton="True" FirstPageText="首页" LastPageText="尾页" LayoutType="Table"
ShowCustomInfoSection="right" ShowPageIndex="false" ShowFirstLast="true" ShowMoreButtons="false"
NextPageText="下一页" PrevPageText="上一页" onpagechanging="AspNetPager1_PageChanging"
PageSize="10" ShowPrevNext="true" ShowInputBox="Auto" PagingButtonSpacing="0" AlwaysShow="True" ShowBoxThreshold="5">
</webdiyer:aspnetpager>
以下是绑定的相关方法
--------------------------------------------------------------------------------------------------
private DataSet SelectDS()
{
string strSql = "SELECT a.* FROM ViewRecommendClassList ";
return Query(strSql);
}
private void BindGridview()
{
DataTable table = tableQuery(SelectDS().Tables[0]);
GridView1.DataSource = table;
AspNetPager1.RecordCount = table.Rows.Count;
AspNetPager1.PageSize = 10;
AspNetPager1.CustomInfoHTML = " <span class=\"pageInfo\">您处在第 " + AspNetPager1.CurrentPageIndex + "/" + AspNetPager1.PageCount + " 页 | 共 <font color='red'>" + AspNetPager1.RecordCount + "</font> 条记录</span>";
GridView1.DataBind();
}
private DataTable tableQuery(DataTable table)
{
DataTable dt = new DataTable();
dt.Columns.Add("CLID", typeof(System.String));
foreach (DataRow row in table.Rows)
{
DataRow dr = dt.NewRow();
(自己设定的名称)dr["CLID"] = row["CL_ID"].ToString(); (这是数据库中的字段)
dt.Rows.Add(dr);
}
return dt;
}
/// <summary>
/// 执行查询语句,返回DataSet
/// </summary>
/// <param name="SQLString">查询语句</param>
/// <returns>DataSet</returns>
public static DataSet Query(string SQLString)
{
using ( SqlConnection sqlConn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
{
DataSet ds = new DataSet();
try
{
sqlConn.Open();
SqlDataAdapter command = new SqlDataAdapter(SQLString, sqlConn);
command.Fill(ds, "ds");
}
catch (System.Data.SqlClient.SqlException ex)
{
throw new Exception(ex.Message);
}
return ds;
}
}
protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
{
AspNetPager1.CurrentPageIndex = e.NewPageIndex;
GridView1.PageIndex = e.NewPageIndex - 1;
BindGridview();
}
--------------------编程问答-------------------- 参考:
http://www.cnblogs.com/insus/articles/1417957.html --------------------编程问答-------------------- 支持9楼的
不错呢 --------------------编程问答-------------------- AspNetPager 很好用 --------------------编程问答-------------------- 拼sql,每次查多少条记录,注:需要标识列支持 --------------------编程问答-------------------- protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
{
AspNetPager1.CurrentPageIndex = e.NewPageIndex;
GridView1.PageIndex = e.NewPageIndex - 1;
BindGridview();
}
DataGridView自己有分页的 --------------------编程问答-------------------- 期待中,看看什么时候,有人会推荐我的分页控件,呵呵。
补充:.NET技术 , ASP.NET