页面代码:
<asp:Repeater id="dlData" runat="server" >
<HeaderTemplate>
<table class="form_eidit" id="form_eidit" style="margin:0" width="100%" border="0" cellpadding="0" cellspacing="0">
<tr ><tb>自定义表格样式(头部标题)</tb></tr>
<tr ><tb>操作数据(头部标题)</tb></tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# DataBinder.Eval(Container.DataItem, "绑定数据源字段名")%></td>
<td class="bold_Font">
<asp:Button ID="btn_excel" runat="server" Text="导出" CssClass="btndelete" BackColor="transparent" CommandArgument='<%# Eval("id") %>' CommandName="Recv" /></td>
</tr>
</ItemTemplate>
<FooterTemplate>
<!--自定义脚部样式-->
</table>
</FooterTemplate>
</asp:Repeater>
<!--分页部分前台代码-->
<div id="page_next"><span>总数<%=incount %>条</span> 当前<%=npage %>/<%=cpage%> <aspnkbutton ID="lkPre" CommandArgument="pre" runat="server" >上一页</aspnkbutton>
<aspnkbutton ID="lkNext" CommandArgument="next" runat="server" >下一页</aspnkbutton></div>
后台源码:
public int incount;
public int npage,cpage;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ViewState["pageindex"] = "0";
BindData();
}
}
private void BindData()
{
DataTable objTable=new DataTable();
DataSet ds1 = dal.GetList(""); //获取数据集
objTable = ds1.table[0];
if (objTable != null && objTable.Rows.Count > 0)
{
DataView objView = objTable.DefaultView;
PagedDataSource objPds = new PagedDataSource();
objPds.DataSource = objView;
objPds.AllowPaging = true;
objPds.PageSize = 10;
objPds.CurrentPageIndex = int.Parse(ViewState["pageindex"].ToString());
if (!objPds.IsFirstPage)
{
lkPre.Enabled = true;
}
else
{
lkPre.Enabled = false;
}
if (!objPds.IsLastPage)
{
lkNext.Enabled = true;
}
else
{
lkNext.Enabled = false;
}
dlData.DataSource = objPds;
dlData.DataBind();
//记录总数
incount = objTable.Rows.Count;
//当前条数
npage = int.Parse(ViewState["pageindex"].ToString())+1;
//总页数
if (incount / 10 != 0)
{
cpage = incount / 10;
}
else
{
cpage = 1;
}
}
}
//分页代码
protected void IndexChanging(object sender, EventArgs e)
{
string strCommand = ((LinkButton)sender).CommandArgument.ToString();
int pageindex = int.Parse(ViewState["pageindex"].ToString());
if (strCommand == "pre")
{
pageindex = pageindex - 1;
}
else
{
pageindex = pageindex + 1;
}
ViewState["pageindex"] = pageindex;
BindData();
}
//数据操作
protected void dlData_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "Recv")
{
string id = e.CommandArgument.ToString();
if (id != "")
{ //获取id号就可以对其数据进行操作 }
}
此代码主要方便初学者,使用,感觉比gridview好使多了,呵呵,拿出来给大家!