请会的人帮我看看Repeater 分页问题,我是新手,完全不懂。
ASP.NET文件<asp:Repeater ID="News" runat="server" OnItemCommand="News_Editor">
<itemtemplate>
<tr align="center" bgcolor="CDDDF4" onmouseover="this.style.backgroundColor='#E4EEFA'"
onmouseout="this.style.backgroundColor=''">
<td align="center" valign="middle"><input type="checkbox" name="checkbox" value="" /></td>
<td align="center" valign="middle"><asp:LinkButton id="news_show" runat="server" Text='<%# Eval("title")%>' />
<%--asp:TextBox runat="server" ID="title" TextMode="MultiLine" Width="328px" Text='<# Eval("title")>'--%></td>
<td align="center" valign="middle"><%# Eval("content")%></td>
<td align="center" valign="middle"><%# Eval("author") %></td>
<td align="center" valign="middle"><%# Eval("type1")%></td>
<td align="center" valign="middle"><%# Eval("date")%></td>
<td align="center" valign="middle">
<asp:Button ID="Editor" runat="server" Text="修改" CommandName="EditorNews" CommandArgument='<%# Eval("ID") %>' /> <asp:Button ID="Delete" runat="server" Text="删除" CommandName="DeleteNews" CommandArgument='<%# Eval("ID") %>' /></td>
</tr>
</itemtemplate>
</asp:Repeater>
ASP.NET.CS文件
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 type1_type1 : System.Web.UI.Page
{
ConnClass MM = new ConnClass();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SetBind();
}
}
protected void SetBind()
{
//取得当前页的页码
int curpage = Convert.ToInt32(this.NowPage.Text);
//使用分页功能
PagedDataSource ps = new PagedDataSource();
//获取数据集
DataSet ds = MM.GetDataSet("select * from News order by Date Desc", "News");
ps.DataSource = ds.Tables["News"].DefaultView;
//是否可以分页
ps.AllowPaging = true;
//显示的数量
ps.PageSize = 12;
//取得当前页的页码
ps.CurrentPageIndex = curpage - 1;
this.PageUp.Enabled = true;
this.PageNext.Enabled = true;
this.BackPage.Enabled = true;
this.HomePage.Enabled = true;
if (curpage == 1)
{
//不显示第一页按钮
this.HomePage.Enabled = false;
//不显示上一页按钮
this.PageUp.Enabled = false;
}
if (curpage == ps.PageCount)
{
//不显示下一页
this.PageNext.Enabled = false;
//不显示最后一页
this.BackPage.Enabled = false;
}
//显示分页数量
this.SumPage.Text = Convert.ToString(ps.PageCount);
News.DataSource = ps;
News.DataBind();
}
//新闻的修改和删除
protected void News_Editor(object source, RepeaterCommandEventArgs e)
{
//根据ID删除新闻
if (e.CommandName == "DeleteNews")
{
MM.ExecSQL("Delete from news where id='"+ e.CommandArgument +"'");
SetBind();
}
if (e.CommandName == "EditorNews")
{
//根据ID修改新闻
MM.ExecSQL("update news set title='"+((TextBox)e.Item .FindControl("title")).Text+"' where id='"+e.CommandArgument+"'");
SetBind();
}
}
//首页
protected void HomePage_Click(object sender, EventArgs e)
{
this.NowPage.Text = "1";
this.SetBind();
}
//上一页
protected void PageUp_Click(object sender, EventArgs e)
{
this.NowPage.Text = Convert.ToString(Convert.ToInt32(this.NowPage.Text) - 1);
this.SetBind();
}
//下一页
protected void PageNext_Click(object sender, EventArgs e)
{
this.NowPage.Text = Convert.ToString(Convert.ToInt32(this.NowPage.Text) + 1);
this.SetBind();
}
//尾页
protected void BackPage_Click(object sender, EventArgs e)
{
this.NowPage.Text = this.SumPage.Text;
this.SetBind();
}
}
--------------------编程问答-------------------- 没说什么问题? --------------------编程问答-------------------- 错误是 对象不支持此属性或方法 --------------------编程问答-------------------- 错误是 对象不支持此属性或方法 --------------------编程问答-------------------- 直接用netpager算了... --------------------编程问答-------------------- 你再看一下,发生异常是因为哪一行?? --------------------编程问答-------------------- 你UI中的上一页下一页呢.
补充:.NET技术 , ASP.NET