首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

Asp.net中类似于QQ相册中的分页功能如何实现

2012-08-21 
Asp.net中类似于QQ相册中的分页功能怎么实现?要这样形式的 上一页 1234 下一页,中间的 有多少也是几个数字

Asp.net中类似于QQ相册中的分页功能怎么实现?
要这样形式的 上一页 1234 下一页,中间的 有多少也是几个数字应该怎么实现?

[解决办法]
参见
http://dotnet.aspx.cc/file/Add-Delete-Update-Edit-Data-With-Paging-in-GridView.aspx
[解决办法]
aspnetrpager分页控件
[解决办法]
Listview+Pager控件
纯JS的话可以JQuery
或者ExtJS
[解决办法]
http://www.open-open.com/ajax/Image.htm
[解决办法]
在Repeater控件内实现分页功能:

页面中代码

<asp:Repeater ID="RptJobList" runat="server" OnItemDataBound="RptJobList_ItemDataBound">

<FooterTemplate>

<td align = "right" height="30" width = "828" colspan="2" style="font-size:10pt;color:#636363;">
<asp:HyperLink colspan="2" style="font-size:10pt;color:#636363;" ID="hlfir" runat="server" Text="第一页"></asp:HyperLink>
&nbsp;
<asp:HyperLink colspan="2" style="font-size:10pt;color:#636363;" ID="hlp" runat="server" Text="上一页"></asp:HyperLink>
&nbsp;
<asp:HyperLink colspan="2" style="font-size:10pt;color:#636363;" ID="hln" runat="server" Text="下一页"></asp:HyperLink>
&nbsp;
<asp:HyperLink colspan="2" style="font-size:10pt;color:#636363;" ID="hlla" runat="server" Text="最后一页"></asp:HyperLink>
&nbsp;&nbsp;&nbsp; 转到第


<asp:DropDownList ID="ddlp" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlp_SelectedIndexChanged" >
</asp:DropDownList>页
</td>

</FooterTemplate>
</asp:Repeater>

.CS代码:

数据绑定函数[自己补充完整即可]

PagedDataSource pds = new PagedDataSource();
pds.DataSource = dt.DefaultView;
pds.AllowPaging = true;//允许分页
pds.PageSize = 20;//单页显示项数
pds.CurrentPageIndex = Convert.ToInt32(Request.QueryString["page"]);

/// <summary>
/// Repeater控件分页 处理
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void RptJobList_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Footer)
{
DropDownList ddlp = (DropDownList)e.Item.FindControl("ddlp");

HyperLink lpfirst = (HyperLink)e.Item.FindControl("hlfir");
HyperLink lpprev = (HyperLink)e.Item.FindControl("hlp");
HyperLink lpnext = (HyperLink)e.Item.FindControl("hln");
HyperLink lplast = (HyperLink)e.Item.FindControl("hlla");
PagedDataSource ps = pds();
string a1 = Request.QueryString["page"];
ps.CurrentPageIndex = Convert.ToInt32(a1);

int n = Convert.ToInt32(ps.PageCount);//n为分页数
int i = Convert.ToInt32(ps.CurrentPageIndex);//i为当前页

Label lblpc = (Label)e.Item.FindControl("lblpc");

//if (!IsPostBack)
//{


for (int j = 0; j < n; j++)
{
ddlp.Items.Add(Convert.ToString(j + 1));
}
//}

string addUrl = "&&testType=" + ddlWorkType.SelectedValue + "&&provinceId=" + ddlProvince.SelectedValue + "&&jobclassId" + ddlJobclass.SelectedValue;
if (i <= 0)
{
lpfirst.Enabled = false;
lpprev.Enabled = false;
lplast.Enabled = true;
lpnext.Enabled = true;
}
else
{
lpprev.NavigateUrl = "?page=" + (i - 1) + addUrl;
}
if (i >= n - 1)
{
lpfirst.Enabled = true;
lplast.Enabled = false;
lpnext.Enabled = false;
lpprev.Enabled = true;
}
else
{
ViewState["i"] = i;
lpnext.NavigateUrl = "?page=" + (i + 1) + addUrl;
}

lpfirst.NavigateUrl = "?page=0" + addUrl; //向本页传递参数page 
lplast.NavigateUrl = "?page=" + (n - 1) + addUrl;

ddlp.SelectedIndex = Convert.ToInt32(ps.CurrentPageIndex);//更新下拉列表框中的当前选中页序号
}
}

/// <summary>
/// 转到第N页
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ddlp_SelectedIndexChanged(object sender, EventArgs e)
{
//脚模板中的下拉列表框更改时激发
string pg = Convert.ToString((Convert.ToInt32(((DropDownList)sender).SelectedValue) - 1));//获取列表框当前选中项
ViewState["pageCount"] = pg;//
Response.Redirect("parttime_joblist.aspx?page=" + pg + "&&testType=" + ddlWorkType.SelectedValue + "&&provinceId=" + ddlProvince.SelectedValue + "&&jobclassId" + ddlJobclass.SelectedValue); //页面转向 
}



本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/hongjiaoli/archive/2010/09/20/5897585.aspx

热点排行