repeater 分页
intid=Convert.ToInt32(Request.QueryString["id"].ToString());DBdb=newDB();stringsql=st...
int id = Convert.ToInt32(Request.QueryString["id"].ToString());
DB db=new DB();
string sql = string.Format("select * from leavewords where id={0}",id);
DataTable dt = db.GetTable(sql);
this.Repeater1.DataSource = dt;
this.Repeater1.DataBind();
已经绑定好了 如何实现分页的功能
补充HTML 页面中 的内容:
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<table><tr><th>提问时间</th><th>标题</th><th>提问人</th><th>是否回复</th></tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:Label ID="lblontime" runat="server" Text='<%#Eval("askdate") %>'></asp:Label></td>
<td>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%#Eval("id","askcontent.aspx?id={0}") %>' Text='<%#Eval("title") %>'></asp:HyperLink>
</td>
<td>
<asp:Label ID="lblusername" runat="server" Text='<%#Eval("username") %>'></asp:Label></td>
<td>
<asp:Label ID="lblstatus" runat="server" Text='<%#Eval("status") %>'></asp:Label></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
请求给分页 repteater里面是用table表 如果是<ul>又怎么办i 展开
DB db=new DB();
string sql = string.Format("select * from leavewords where id={0}",id);
DataTable dt = db.GetTable(sql);
this.Repeater1.DataSource = dt;
this.Repeater1.DataBind();
已经绑定好了 如何实现分页的功能
补充HTML 页面中 的内容:
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<table><tr><th>提问时间</th><th>标题</th><th>提问人</th><th>是否回复</th></tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:Label ID="lblontime" runat="server" Text='<%#Eval("askdate") %>'></asp:Label></td>
<td>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%#Eval("id","askcontent.aspx?id={0}") %>' Text='<%#Eval("title") %>'></asp:HyperLink>
</td>
<td>
<asp:Label ID="lblusername" runat="server" Text='<%#Eval("username") %>'></asp:Label></td>
<td>
<asp:Label ID="lblstatus" runat="server" Text='<%#Eval("status") %>'></asp:Label></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
请求给分页 repteater里面是用table表 如果是<ul>又怎么办i 展开
2个回答
展开全部
我做过这样的:public partial class Repeater : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.Label2.Text ="1";
databindrepeater();
}
}
private void databindrepeater()
{
int curPage =Convert.ToInt32(this.Label2.Text);
SqlConnection con = DB.createCon();
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = new SqlCommand("select * from person", con);
DataSet ds = new DataSet();
sda.Fill(ds, "person");
PagedDataSource pds = new PagedDataSource();
pds.DataSource = ds.Tables["person"].DefaultView ;
pds.AllowPaging = true;
pds.CurrentPageIndex=curPage - 1;
pds.PageSize = 2;
if (curPage == 1)
{
this.btnFont.Enabled = false;
}
else
{
this.btnFont.Enabled = true;
}
if (curPage == pds.PageCount)
{
this.btnNext.Enabled = false;
}
else
{
this.btnNext.Enabled = true;
}
this.Repeater1.DataSource =pds;
this.Repeater1.DataBind();
}
protected void btnFont_Click(object sender, EventArgs e)
{
this.Label2.Text = Convert.ToString(Convert.ToInt32(this.Label2.Text) - 1);
this.databindrepeater();
}
protected void btnNext_Click(object sender, EventArgs e)
{
this.Label2.Text = Convert.ToString(Convert.ToInt32(this.Label2.Text) + 1);
this.databindrepeater();
}
}
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.Label2.Text ="1";
databindrepeater();
}
}
private void databindrepeater()
{
int curPage =Convert.ToInt32(this.Label2.Text);
SqlConnection con = DB.createCon();
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = new SqlCommand("select * from person", con);
DataSet ds = new DataSet();
sda.Fill(ds, "person");
PagedDataSource pds = new PagedDataSource();
pds.DataSource = ds.Tables["person"].DefaultView ;
pds.AllowPaging = true;
pds.CurrentPageIndex=curPage - 1;
pds.PageSize = 2;
if (curPage == 1)
{
this.btnFont.Enabled = false;
}
else
{
this.btnFont.Enabled = true;
}
if (curPage == pds.PageCount)
{
this.btnNext.Enabled = false;
}
else
{
this.btnNext.Enabled = true;
}
this.Repeater1.DataSource =pds;
this.Repeater1.DataBind();
}
protected void btnFont_Click(object sender, EventArgs e)
{
this.Label2.Text = Convert.ToString(Convert.ToInt32(this.Label2.Text) - 1);
this.databindrepeater();
}
protected void btnNext_Click(object sender, EventArgs e)
{
this.Label2.Text = Convert.ToString(Convert.ToInt32(this.Label2.Text) + 1);
this.databindrepeater();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询