girdview分页及原理,在线,马上给分! gridview1.PageIndex = Request.QueryString["page"]; 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 GridView自己生成的分页,是一次把数据库中所有的数据提取出来,再分页。所以效率不是很好。如果数据量大的话,是不推荐这种分页的。要使用高效的分页,一般采取楼主所说的(news.asp?page=2)根据需要来分页,这样要写自己的分页代码,分页链接。网上教程很多,楼主自己搜一下。 FBug(花知) :这个我知道我希望是能在(客户端)通过一种方式定位到某页! GridView的分页原理是用时间换空间,而别的分页则是用空间换时间明白这个就可以了csdn的分页 就是用空间换时间, GridView自己生成的分页,是一次把数据库中所有的数据提取出来,再分页。所以效率不是很好。如果数据量大的话,是不推荐这种分页的。 我希望是能在(客户端)通过一种方式定位到某页!----------那你不能使用gridview内置分页方法实现。 例如这个网址中的下一页http://www.gxape.com.cn/Trade/CompanyList.aspx还有这个网页中的第几页http://www.ulam.cn/PostList.aspx?smallid=16我怎么不通过点击网页提供的“页码”或“上下页”链接而直接跳转某页 GridView自己生成的分页,是一次把数据库中所有的数据提取出来,再分页。所以效率不是很好。如果数据量大的话,是不推荐这种分页的。大家都这么说,可是你么都错了,这都是大家普遍的误解,其实gridview,datagrid都是可以想别的分页控件一样用存储过程分页的,只是少了很多定义导航样式显示花样而已。GridView自己生成的分页,是一次把数据库中所有的数据提取出来,再分页,这是CSDN上边最误导人的,我也是那天无聊看了下MSDN所以才知道不是这样的 楼上老兄:现在的信息采集工具不是这样吗我看看asp.net的gridview的分页能不能被它采集(需要采集必须得到每一页) 为什么非用GridView,LZ说的那效果,用Repeater,DataList都可能实现的,配合数据库端的存储过,就可能实现百万或千万级的分页了(效率非常高的),至于什么什么到某一页,也比较实现实现,去网上找一人上JS的分页代码,绑定路径就行了 看来我的意思表达有问题我要解决的问题:◆gridview邦定数据源后自动生成分页的原理(不是自己写)◆生成的页面里的分页可不可以通过客户端获得 例如这个网址中的下一页 http://www.gxape.com.cn/Trade/CompanyList.aspx 还有这个网页中的第几页 http://www.ulam.cn/PostList.aspx?smallid=16 我怎么不通过点击网页提供的“页码”或“上下页”链接而直接跳转某页◆重点是第二个问题 http://www.ulam.cn/PostList.aspx?smallid=16 我怎么不通过点击网页提供的“页码”或“上下页”链接而直接跳转某页 -------------------------------- so hard. 单一的用web页实现有点困难。 其实这类分页方法google baidu也是抓不到第二页的数据的。 <table border="0" align="center" cellpadding="0" cellspacing="0" class="css" style="width: 678px"> <tr> <td align="center" valign="bottom" style="width: 710px"><asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Width="100%" CssClass="css" CellPadding="2" AllowSorting="True" DataKeyNames="id" PageSize="1" OnRowCreated="GridView1_RowCreated" OnRowDeleting="GridView1_RowDeleting" OnRowUpdating="GridView1_RowUpdating" > <Columns> <asp:BoundField DataField="Number" HeaderText="编号"> <ItemStyle Width="40px" Height="22px" VerticalAlign="Middle" /> </asp:BoundField> <asp:BoundField DataField="fl" HeaderText="新闻类别"> <ItemStyle Width="70px" Height="22px" /> </asp:BoundField> <asp:BoundField DataField="title" HeaderText="新闻标题"> <ItemStyle HorizontalAlign="Left" Height="22px" /> </asp:BoundField> <asp:BoundField DataField="timea" HeaderText="发布时间"> <ItemStyle Width="70px" Height="22px" /> </asp:BoundField> <asp:TemplateField HeaderText="修改"> <ItemTemplate> <asp:LinkButton ID="LinkButton1" runat="server" CommandName="Update">修改</asp:LinkButton> </ItemTemplate> <ItemStyle Height="20px" Width="40px" /> </asp:TemplateField> <asp:CommandField ShowDeleteButton="True" HeaderText="删除"> <ItemStyle Width="40px" Height="22px" /> </asp:CommandField> </Columns> <PagerSettings Mode="NextPreviousFirstLast" Visible="False" /> <HeaderStyle BackColor="#E0E0E0" Height="22px" /> </asp:GridView> <asp:Panel ID="Panel1" runat="server" Height="24px" HorizontalAlign="Center" Width="500px"> <asp:Button CommandArgument="first" CommandName="page" ID="Button1" OnClick="Button1_Click" runat="server" Text=" 首 页 " CssClass="sxbka" /> <asp:Button ID="Button2" runat="server" CommandArgument="prev" CommandName="page" Text=" 上一页 " OnClick="Button1_Click" CssClass="sxbka" /> <asp:Button ID="Button3" runat="server" CommandArgument="next" CommandName="page" Text=" 下一页 " OnClick="Button1_Click" CssClass="sxbka" /> <asp:Button ID="Button4" runat="server" CommandArgument="last" CommandName="page" Text=" 末 页 " OnClick="Button1_Click" CssClass="sxbka" /> </asp:Panel></td> </tr> </table>后台代码using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;public partial class pople_admin_newlist : System.Web.UI.Page{ public Code cal = new Code();//这里是类 里面数据库连接等 protected void Page_Load(object sender, EventArgs e) { if (Session["username"] == null || Session["username"] == "") { Response.Redirect("login.aspx"); } else { if (!Page.IsPostBack) { bind(); } } } public void bind() { DataSet ds = cal.LoadNews(DropYa.SelectedValue.Trim(),DropFl.SelectedValue.Trim()); DataColumn mytable = ds.Tables[0].Columns.Add("Number", System.Type.GetType("System.String")); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { ds.Tables[0].Rows[i]["Number"] = (i + 1).ToString(); if(ds.Tables[0].Rows[i]["fl"].ToString()=="1") { ds.Tables[0].Rows[i]["fl"] = "企业动态"; } else if (ds.Tables[0].Rows[i]["fl"].ToString() == "2") { ds.Tables[0].Rows[i]["fl"] = "行业动态"; } } GridView1.AllowPaging = true; GridView1.PageSize = 20; GridView1.DataSource = ds.Tables[0]; GridView1.DataBind(); if (GridView1.PageIndex == 0) { Button1.Enabled = false; Button2.Enabled = false; } else { Button1.Enabled = true; Button2.Enabled = true; } if (GridView1.PageIndex == GridView1.PageCount - 1) { Button3.Enabled = false; Button4.Enabled = false; } else { Button3.Enabled = true; Button4.Enabled = true; } } protected void Button1_Click(object sender, EventArgs e) { switch (((Button)sender).CommandArgument.ToString()) { case "first": GridView1.PageIndex = 0; break; case "last": GridView1.PageIndex = GridView1.PageCount - 1; break; case "prev": GridView1.PageIndex = GridView1.PageIndex - 1; break; case "next": GridView1.PageIndex = GridView1.PageIndex + 1; break; } bind(); } protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) {//判断当前行是数据行, e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#E0E0E0';"); e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;"); } } protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { string id = GridView1.DataKeys[e.RowIndex]["id"].ToString(); int back = cal.DelNews(id); if (back > 0) { Jscript.Show("删除成功"); bind(); } } protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { string id = GridView1.DataKeys[e.RowIndex]["id"].ToString(); Response.Redirect("admin_newxg.aspx?id="+id); } protected void DropFl_SelectedIndexChanged(object sender, EventArgs e) { bind(); } protected void DropYa_SelectedIndexChanged(object sender, EventArgs e) { bind(); }} 用repeater控件出问题,只可以显示第一条记录,其他的被覆盖了 跪求一个存储过程 求最简单的asp.net mvc的小例子 挑战你,怎么样! 如何把ecxel数据导入到数据库中 DataList不显示空格的问题 关于FreeTextBox的问题,求助啊! 此人没道德 谁能把它的网站给黑啦 为了缓解压力出一道谜语:交通最发达的地方 。答一个国外城市名 不知如何来实现这个友好询问功能呢? !!!!!!!!!!!!!!!!!!!!!登录注册的问题啊,救命啊~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 关于DataSourceId的难题
要使用高效的分页,一般采取楼主所说的(news.asp?page=2)根据需要来分页,这样要写自己的分页代码,分页链接。网上教程很多,楼主自己搜一下。
这个我知道我希望是能在(客户端)通过一种方式定位到某页!
----------那你不能使用gridview内置分页方法实现。
http://www.ulam.cn/PostList.aspx?smallid=16我怎么不通过点击网页提供的“页码”或“上下页”链接而直接跳转某页
大家都这么说,可是你么都错了,这都是大家普遍的误解,其实gridview,datagrid都是可以想别的分页控件一样用存储过程分页的,只是少了很多定义导航样式显示花样而已。
GridView自己生成的分页,是一次把数据库中所有的数据提取出来,再分页,这是CSDN上边最误导人的,我也是那天无聊看了下MSDN所以才知道不是这样的
现在的信息采集工具不是这样吗
我看看asp.net的gridview的分页能不能被它采集(需要采集必须得到每一页)
http://www.ulam.cn/PostList.aspx?smallid=16 我怎么不通过点击网页提供的“页码”或“上下页”链接而直接跳转某页◆重点是第二个问题
-------------------------------- so hard.
<tr>
<td align="center" valign="bottom" style="width: 710px"><asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Width="100%" CssClass="css" CellPadding="2" AllowSorting="True" DataKeyNames="id" PageSize="1" OnRowCreated="GridView1_RowCreated" OnRowDeleting="GridView1_RowDeleting" OnRowUpdating="GridView1_RowUpdating" >
<Columns>
<asp:BoundField DataField="Number" HeaderText="编号">
<ItemStyle Width="40px" Height="22px" VerticalAlign="Middle" />
</asp:BoundField>
<asp:BoundField DataField="fl" HeaderText="新闻类别">
<ItemStyle Width="70px" Height="22px" />
</asp:BoundField>
<asp:BoundField DataField="title" HeaderText="新闻标题">
<ItemStyle HorizontalAlign="Left" Height="22px" />
</asp:BoundField>
<asp:BoundField DataField="timea" HeaderText="发布时间">
<ItemStyle Width="70px" Height="22px" />
</asp:BoundField>
<asp:TemplateField HeaderText="修改">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="Update">修改</asp:LinkButton>
</ItemTemplate>
<ItemStyle Height="20px" Width="40px" />
</asp:TemplateField>
<asp:CommandField ShowDeleteButton="True" HeaderText="删除">
<ItemStyle Width="40px" Height="22px" />
</asp:CommandField>
</Columns>
<PagerSettings Mode="NextPreviousFirstLast" Visible="False" />
<HeaderStyle BackColor="#E0E0E0" Height="22px" />
</asp:GridView>
<asp:Panel ID="Panel1" runat="server" Height="24px" HorizontalAlign="Center" Width="500px">
<asp:Button CommandArgument="first" CommandName="page" ID="Button1" OnClick="Button1_Click" runat="server" Text=" 首 页 " CssClass="sxbka" />
<asp:Button ID="Button2" runat="server" CommandArgument="prev" CommandName="page" Text=" 上一页 " OnClick="Button1_Click" CssClass="sxbka" />
<asp:Button ID="Button3" runat="server"
CommandArgument="next" CommandName="page" Text=" 下一页 " OnClick="Button1_Click" CssClass="sxbka" />
<asp:Button ID="Button4" runat="server" CommandArgument="last" CommandName="page"
Text=" 末 页 " OnClick="Button1_Click" CssClass="sxbka" />
</asp:Panel></td>
</tr>
</table>后台代码
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class pople_admin_newlist : System.Web.UI.Page
{
public Code cal = new Code();//这里是类 里面数据库连接等
protected void Page_Load(object sender, EventArgs e)
{
if (Session["username"] == null || Session["username"] == "")
{
Response.Redirect("login.aspx");
}
else
{
if (!Page.IsPostBack)
{
bind();
}
}
} public void bind()
{
DataSet ds = cal.LoadNews(DropYa.SelectedValue.Trim(),DropFl.SelectedValue.Trim());
DataColumn mytable = ds.Tables[0].Columns.Add("Number", System.Type.GetType("System.String"));
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
ds.Tables[0].Rows[i]["Number"] = (i + 1).ToString();
if(ds.Tables[0].Rows[i]["fl"].ToString()=="1")
{
ds.Tables[0].Rows[i]["fl"] = "企业动态";
}
else if (ds.Tables[0].Rows[i]["fl"].ToString() == "2")
{
ds.Tables[0].Rows[i]["fl"] = "行业动态";
}
}
GridView1.AllowPaging = true;
GridView1.PageSize = 20;
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind(); if (GridView1.PageIndex == 0)
{
Button1.Enabled = false;
Button2.Enabled = false;
}
else
{
Button1.Enabled = true;
Button2.Enabled = true;
}
if (GridView1.PageIndex == GridView1.PageCount - 1)
{
Button3.Enabled = false;
Button4.Enabled = false;
}
else
{
Button3.Enabled = true;
Button4.Enabled = true;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
switch (((Button)sender).CommandArgument.ToString())
{
case "first":
GridView1.PageIndex = 0;
break;
case "last":
GridView1.PageIndex = GridView1.PageCount - 1;
break;
case "prev":
GridView1.PageIndex = GridView1.PageIndex - 1;
break;
case "next":
GridView1.PageIndex = GridView1.PageIndex + 1;
break;
}
bind();
}
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{//判断当前行是数据行,
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#E0E0E0';");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
}
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string id = GridView1.DataKeys[e.RowIndex]["id"].ToString();
int back = cal.DelNews(id);
if (back > 0)
{
Jscript.Show("删除成功");
bind();
} }
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string id = GridView1.DataKeys[e.RowIndex]["id"].ToString();
Response.Redirect("admin_newxg.aspx?id="+id);
} protected void DropFl_SelectedIndexChanged(object sender, EventArgs e)
{
bind();
}
protected void DropYa_SelectedIndexChanged(object sender, EventArgs e)
{
bind();
}
}