repeater嵌套的问题

mznxbcv000 2011-12-08 05:46:50
各位大侠,小弟在此请教一下:
在没有运用嵌套之前,分页是可以的。但是使用嵌套后,分页就不好使了,页数是正常的。但是第一页就把所有数据都显示出来了,而且点击其他页码,也是显示的全部数据。这是怎么回事呢?
...全文
112 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
mznxbcv000 2011-12-09
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 taomanman 的回复:]
代码问题,无码无真相!
[/Quote]
代码是封装好的,没法复制过来。就是repeater里面嵌套了一个repeater
暖枫无敌 2011-12-09
  • 打赏
  • 举报
回复
代码问题,无码无真相!
csdn_aspnet 2011-12-09
  • 打赏
  • 举报
回复
你嵌套了什么?

Default.aspx
1<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
2<%@ Import Namespace="System.Data" %>
3
4<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
6<html xmlns="http://www.w3.org/1999/xhtml" >
7<head runat="server">
8 <title>Untitled Page</title>
9</head>
10<body>
11 <form id="form1" runat="server">
12 <div>
13 <asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">
14 <HeaderTemplate>
15 <table width="500">
16 <tr style="background-color:#ccffcc;">
17 <td>
18 name
19 </td>
20 <td>
21 title
22 </td>
23 <td>
24 content
25 </td>
26 <td>
27 reply
28 </td>
29 </tr>
30 </HeaderTemplate>
31 <ItemTemplate>
32 <tr>
33 <td>
34 <a href='Default1.aspx?id=<%#Eval("id") %>'><%#Eval("name") %></a>
35 </td>
36 <td>
37 <%#Eval("title") %>
38 </td>
39 <td>
40 <%#Eval("content") %>
41 </td>
42 <td>
43 <asp:Repeater ID="Repeater2" runat="server" DataSource='<%# Eval("myrelation")%>'>
44 <ItemTemplate>
45 <%#Eval("[\"replyContent\"]") %>
46 <hr size="2pt"/>
47
48 <%--<%#DataBinder.Eval(Container.DataItem,"replyTitle") %>--%>
49 </ItemTemplate>
50 </asp:Repeater>
51 </td>
52 </tr>
53 </ItemTemplate>
54 <SeparatorTemplate>
55 <tr>
56 <td colspan="4">
57 <hr size="2pt" />
58 </td>
59 </tr>
60 </SeparatorTemplate>
61 <FooterTemplate>
62 <tr>
63 <td colspan="4" style="font-size:12pt;color:#0099ff; background-color:#e6feda;">
64 共<asp:Label ID="lblpc" runat="server" Text="Label"></asp:Label>页 当前为第<asp:Label ID="lblp"
65 runat="server" Text="Label"></asp:Label>页
66 <asp:HyperLink ID="lpfirst" runat="server">首页</asp:HyperLink>
67 <asp:HyperLink ID="lpprev" runat="server">上一页</asp:HyperLink>
68 <asp:HyperLink ID="lpnext" runat="server">下一页</asp:HyperLink>
69 <asp:HyperLink ID="lplast" runat="server">末页</asp:HyperLink>
70 </td>
71 </tr>
72 </table>
73 </FooterTemplate>
74 </asp:Repeater>
75  
76
77 </div>
78 </form>

Default.aspx.cs
using System;
using System.Data;
using System.Configuration;
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;
using System.Data.OleDb;


public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Repeater1.DataSource = pds();//通过类PagedDataSource来实现分页,pds()方法返回一个类PagedDataSource的对象pds
Repeater1.DataBind();
}
}
private PagedDataSource pds()
{
string connectionString = "provider=microsoft.jet.oledb.4.0;data source=D:/WebSites/Repeater/App_Data/student.mdb";
OleDbConnection myConnetion = new OleDbConnection(connectionString);
OleDbDataAdapter oda = new OleDbDataAdapter("select * from message", myConnetion);
DataSet ds = new DataSet();
oda.Fill(ds, "message");
OleDbDataAdapter oda2 = new OleDbDataAdapter("select * from reply", myConnetion);
oda2.Fill(ds, "reply");
ds.Relations.Add("myrelation",ds.Tables["message"].Columns["id"],ds.Tables["reply"].Columns["id"]);//新增一个关系myrelation把表message和reply通过字段id连接起来
PagedDataSource pds=new PagedDataSource();
pds.DataSource=ds.Tables["message"].DefaultView;
pds.AllowPaging=true;//允许分页
pds.PageSize=2;//分页数
pds.CurrentPageIndex=Convert.ToInt32(Request.QueryString["page"]);//当前页CurrentPageIndex,通过获得传来的参数page来设置
return pds;
}

protected void Repeater1_ItemDataCommand(object source, RepeaterCommandEventArgs e)
{

}
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Footer)
{
int n = Convert.ToInt32( pds().PageCount);//n为分页数
int i = Convert.ToInt32(pds().CurrentPageIndex);//i为当前页
Label lblpc =(Label) e.Item.FindControl("lblpc");
lblpc.Text = n.ToString();
Label lblp = (Label)e.Item.FindControl("lblp");
lblp.Text = Convert.ToString(pds().CurrentPageIndex+1);

HyperLink lpfirst = (HyperLink)e.Item.FindControl("lpfirst");
HyperLink lpprev = (HyperLink)e.Item.FindControl("lpprev");
HyperLink lpnext = (HyperLink)e.Item.FindControl("lpnext");
HyperLink lplast = (HyperLink)e.Item.FindControl("lplast");
lpfirst.NavigateUrl = "?page=0";//向Default.aspx(就是本页)传递参数page
lplast.NavigateUrl = "?page="+(n-1);

if (i <= 0)
{
lpfirst.Enabled = false;
lpprev.Enabled = false;
lplast.Enabled = true;
lpnext.Enabled = true;
}
else
{
lpprev.NavigateUrl = "?page=" + (i - 1);
}
if (i >= n - 1)
{
lpfirst.Enabled = true;
lplast.Enabled = false;
lpnext.Enabled = false;
lpprev.Enabled = true;
}
else
{
lpnext.NavigateUrl = "?page=" + (i + 1);
}
}
}
}


110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧