我在一个页面里用repeate控件绑定了很多的内容。是好几个repeate控件。没有传什么ID进来我想问下,我可以实现这么多repeate控件中的数据分页么?如果可以,代码 和调用部分麻烦贴下,100分绝对给你。在线等哈
解决方案 »
- sso的一个forms认证问题(急)
- 关于sqlparameter的输出参数声明
- TabContainer传值问题
- 高分求救 GridView 自定义列取值问题
- 有什么方法可看出是用VS作程序还是DreamweaverMX作程序?
- 求一段代码,简单链表结构
- 添加分级审查后系统运行非常慢,期待解决的方法!!!!希望高手解决!!
- petshop中的category中的控件怎会出现错误了.
- 有关后绑定问题,我知道在ASP里是用Createobject,在ASP.NET中呢?
- 请教:在用Insert语句添加记录的同时,是否可以在添加后马上返回该记录?
- 如何做站内搜索?
- 网站还是不稳定,真不知道是怎么会回事!特别郁闷,哪位大侠能给点建议?
如果要分页。可以用吴旗娃的分页控件。
每次只从db 取一页数据出来.绑定repeate
string sql = "select * from [Liuyan] order by id desc";
DataSet Ds = DataAccess.DataAccess.GetDataSet(sql); //使用PagedDataSource来实现分页
PagedDataSource pds = new PagedDataSource();
pds.DataSource = Ds.Tables[0].DefaultView;
pds.AllowPaging = true;
pds.PageSize = 10;
pds.CurrentPageIndex = Convert.ToInt32(this.labPage.Text) - 1;
Repeater1.DataSource = pds;
Repeater1.DataBind();
ADO.NET是对Microsoft ActiveX Data Objects (ADO)一个跨时代的改进,它提供了平台互用性和可伸缩的数据访问。由于传送的数据都是XML格式的,因此任何能够读取XML格式的应用程序都可以进行数据处理。事实上,接受数据的组件不一定要是ADO .NET组件,它可以是基于一个Microsoft Visual Studio的解决方案,也可以是任何运行在其它平台上的任何应用程序。以前做数据库访问的时候,需要一直与数据库保持连接,直到获取完所有满足需要的数据之后才会断开数据库连接,这种数据库访问方式称之为连接式数据访问技术。相比于以前的连接式数据访问技术,ADO.NET除了提供连接式数据访问技术之外,还提供了另一种断开式解决方案,那就是在内存中模拟一个数据库,也就是内存中的数据库。我们知道在实际的数据库技术中,每个数据库就是一个业务逻辑单元,一般来说这个数据库包含了实现一个应用软件或者一个网站所需要的全部数据。
本篇中还讲述了自定义分页在数据库层的理论。用AjaxPro实现无刷新翻页效果及数据库分页技术介绍
题外话:这其中大部分代码都是从我的项目中摘取出来的,不过为了演示整个程序的框架结构,所以在演示程序代码里不会有大量与实际相关的业务逻辑处理,但是这并不妨碍你利用这些理论做出复杂的、完善的应用。一、数据库分页理论在实际项目中经常会遇到一个表里有几K、几M以上的数据,而呈现给用户时并不会一下子都显示出来,所以都是分批展示给用户,这样一来可以减小网络传输量,二来也减轻服务器压力。本文展示了在数据库中如何实现分页,如何利用AjaxPro实现无刷新分页。
看看
调试和代码全部指望别人 自己做什么呢?有思路 和主要代码就可以了!
DataList分页:
http://www.cnblogs.com/insus/articles/1418224.htmlGridView分页:
http://www.cnblogs.com/insus/articles/1417957.html
protected DataSet ds = new DataSet();
......
private void GridViewBind()
{
string Connstring = ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(Connstring);
SqlDataAdapter sda = new SqlDataAdapter("select GroupID,Name,Phonenumber,Email,G_ID from [Group]", con);
DataSet ds = new DataSet();
sda.Fill(ds,"[Group]");
int curPage = Convert.ToInt32(this.Label1.Text);
PagedDataSource ps = new PagedDataSource();
ps.DataSource = ds.Tables["[Group]"].DefaultView;
ps.AllowPaging = true;
ps.PageSize = 10;
ps.CurrentPageIndex = curPage - 1;
this.LinkButton2.Enabled = true;
this.LinkButton3.Enabled = true;
前台.aspx:
第<asp:Label ID="Label1" runat="server" Text="Label" ></asp:Label>页
共<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>页
<asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click1">首页</asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" onclick="LinkButton2_Click">上一页</asp:LinkButton>
<asp:LinkButton ID="LinkButton3" runat="server" onclick="LinkButton3_Click1">下一页</asp:LinkButton>
<asp:LinkButton ID="LinkButton4" runat="server" onclick="LinkButton4_Click">末页</asp:LinkButton>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
if (curPage == 1)
{
this.LinkButton2.Enabled = false;
}
if (curPage == ps.PageCount)
{
this.LinkButton3.Enabled = false;
}
this.Repeater1.DataSource = ps;
this.Repeater1.DataBind();
Label2.Text = (ps.PageCount).ToString();
DropDownList1.Items.Clear();
for (int i = 1; i < ps.PageCount + 1; i++)
{
DropDownList1.Items.Add(i.ToString());
}
DropDownList1.SelectedIndex = Convert.ToInt32(Label1.Text) - 1;
}
protected void Button1_Click(object sender, EventArgs e)
{
this.Label1.Text = Convert.ToString(Convert.ToInt32(this.Label1.Text) - 1);
this.GridViewBind();
} protected void LinkButton1_Click1(object sender, EventArgs e)
{
this.Label1.Text = "1";
this.GridViewBind();
}
protected void LinkButton4_Click(object sender, EventArgs e)
{
this.Label1.Text = Label2.Text;
this.GridViewBind();
}
protected void LinkButton2_Click(object sender, EventArgs e)
{
this.Label1.Text = Convert.ToString(Convert.ToInt32(this.Label1.Text) - 1);
this.GridViewBind();
}
protected void LinkButton3_Click1(object sender, EventArgs e)
{
this.Label1.Text=Convert.ToString(Convert.ToInt32(this.Label1.Text)+1);
this.GridViewBind();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
this.Label1.Text = DropDownList1.SelectedItem.Text;
this.GridViewBind();
}
把_部分改一下就可以了~
我已经验证过了,记得给分啊~
哈哈~
protected DataSet ds = new DataSet();
......
private void GridViewBind()
{
string Connstring = ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(Connstring);
SqlDataAdapter sda = new SqlDataAdapter("select GroupID,Name,Phonenumber,Email,G_ID from [Group]", con);
DataSet ds = new DataSet();
sda.Fill(ds,"[Group]");
int curPage = Convert.ToInt32(this.Label1.Text);
PagedDataSource ps = new PagedDataSource();
ps.DataSource = ds.Tables["[Group]"].DefaultView;
ps.AllowPaging = true;
ps.PageSize = 10;
ps.CurrentPageIndex = curPage - 1;
this.LinkButton2.Enabled = true;
this.LinkButton3.Enabled = true;
if (curPage == 1)
{
this.LinkButton2.Enabled = false;
}
if (curPage == ps.PageCount)
{
this.LinkButton3.Enabled = false;
}
this.Repeater1.DataSource = ps;
this.Repeater1.DataBind();
Label2.Text = (ps.PageCount).ToString();
DropDownList1.Items.Clear();
for (int i = 1; i < ps.PageCount + 1; i++)
{
DropDownList1.Items.Add(i.ToString());
}
DropDownList1.SelectedIndex = Convert.ToInt32(Label1.Text) - 1;
}
protected void Button1_Click(object sender, EventArgs e)
{
this.Label1.Text = Convert.ToString(Convert.ToInt32(this.Label1.Text) - 1);
this.GridViewBind();
} protected void LinkButton1_Click1(object sender, EventArgs e)
{
this.Label1.Text = "1";
this.GridViewBind();
}
protected void LinkButton4_Click(object sender, EventArgs e)
{
this.Label1.Text = Label2.Text;
this.GridViewBind();
}
protected void LinkButton2_Click(object sender, EventArgs e)
{
this.Label1.Text = Convert.ToString(Convert.ToInt32(this.Label1.Text) - 1);
this.GridViewBind();
}
protected void LinkButton3_Click1(object sender, EventArgs e)
{
this.Label1.Text=Convert.ToString(Convert.ToInt32(this.Label1.Text)+1);
this.GridViewBind();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
this.Label1.Text = DropDownList1.SelectedItem.Text;
this.GridViewBind();
}
前台.aspx:
第 <asp:Label ID="Label1" runat="server" Text="Label" > </asp:Label>页
共 <asp:Label ID="Label2" runat="server" Text="Label"> </asp:Label>页
<asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click1">首页 </asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" onclick="LinkButton2_Click">上一页 </asp:LinkButton>
<asp:LinkButton ID="LinkButton3" runat="server" onclick="LinkButton3_Click1">下一页 </asp:LinkButton>
<asp:LinkButton ID="LinkButton4" runat="server" onclick="LinkButton4_Click">末页 </asp:LinkButton>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>