asp.net datagrid 控件分页问题
asp.net datagrid 控件中分页如果我想显示的分页的页码 为 “ 上一页 1 2 3 下一页 ” 这样的该怎么写代码呢?谢谢--------------------编程问答--------------------
用aspnetpager分页。。。 --------------------编程问答-------------------- 参考 --------------------编程问答--------------------
这里可以看一些属性的设置。。。。 --------------------编程问答--------------------
++ --------------------编程问答--------------------
当然还有其他分页控件和其他处理办法.
具体可以一个一个看看. --------------------编程问答--------------------
这个在哪边下载呀 --------------------编程问答-------------------- 最近在做的,举个例子,你可以参考下
前台的代码:
<div id="footerpage" style=" height:25px; width:800px">
<table style="width: 800px; background-color:#B5C7DE ;color:#4A3C8C;" cellpadding="0" cellspacing="0">
<tr align="right">
<td></td>
<td style="font-size: 9pt; height: 25px; text-align: right">
<asp:Label ID="currentpage" runat="server" Text="当前页码为:"></asp:Label>
[
<asp:Label ID="labCurrentPage" runat="server" Text="1"></asp:Label>
]
<asp:Label ID="countpage" runat="server" Text="总页码为:"></asp:Label>
[
<asp:Label ID="labCountPage" runat="server"></asp:Label>
]<asp:LinkButton ID="lnkbtnOne" runat="server" Font-Underline="False" ForeColor="black"
OnClick="lnkbtnOne_Click">第一页</asp:LinkButton>
<asp:LinkButton ID="lnkbtnUp" runat="server" Font-Underline="False" ForeColor="black"
OnClick="lnkbtnUp_Click">上一页</asp:LinkButton>
<asp:LinkButton ID="lnkbtnNext" runat="server" Font-Underline="False" ForeColor="black"
OnClick="lnkbtnNext_Click">下一页</asp:LinkButton>
<asp:LinkButton ID="lnkbtnBack" runat="server" Font-Underline="False" ForeColor="black"
OnClick="lnkbtnBack_Click">最后一页</asp:LinkButton> </td>
</tr>
</table>
</div>
对应的按钮响应事件:
protected void lnkbtnOne_Click(object sender, EventArgs e)
{
this.labCurrentPage.Text = "1";
this.datalistBind();
}
protected void lnkbtnUp_Click(object sender, EventArgs e)
{
this.labCurrentPage.Text = Convert.ToString(Convert.ToInt32(this.labCurrentPage.Text) - 1);
this.datalistBind();
}
protected void lnkbtnNext_Click(object sender, EventArgs e)
{
this.labCurrentPage.Text = Convert.ToString(Convert.ToInt32(this.labCurrentPage.Text) + 1);
this.datalistBind();
}
protected void lnkbtnBack_Click(object sender, EventArgs e)
{
this.labCurrentPage.Text = this.labCountPage.Text;
this.datalistBind();
}
数据绑定:
public void datalistBind()
{
Model.Forum.ForumModule model = new Model.Forum.ForumModule();
BLL.Forum.ForumManageBLL forumbll = new BLL.Forum.ForumManageBLL();
DataSet ds = forumbll.GetModuleDataSet1();
PagedDataSource pds = new PagedDataSource();
pds.DataSource = ds.Tables[0].DefaultView;
pds.AllowPaging = true;
pds.PageSize = 5;
int CurrentPageNO = Convert.ToInt32(this.labCurrentPage.Text);
pds.CurrentPageIndex = CurrentPageNO - 1;
this.lnkbtnOne.Enabled = true;
this.lnkbtnUp.Enabled = true;
this.lnkbtnNext.Enabled = true;
this.lnkbtnBack.Enabled = true;
if (CurrentPageNO == 1)
{
this.lnkbtnOne.Enabled = false;
this.lnkbtnUp.Enabled = false;
if (CurrentPageNO == pds.PageCount)
{
this.lnkbtnNext.Enabled = false;
this.lnkbtnBack.Enabled = false;
}
else
{
this.lnkbtnNext.Enabled = true;
this.lnkbtnBack.Enabled = true;
}
}
else if (CurrentPageNO == pds.PageCount)
{
this.lnkbtnOne.Enabled = true;
this.lnkbtnUp.Enabled = true;
this.lnkbtnNext.Enabled = false;
this.lnkbtnBack.Enabled = false;
}
else
{
this.lnkbtnBack.Enabled = true;
this.lnkbtnNext.Enabled = true;
this.lnkbtnUp.Enabled = true;
this.lnkbtnOne.Enabled = true;
}
this.labCountPage.Text = Convert.ToString(pds.PageCount);
this.topiclist.DataSource = pds;
this.topiclist.DataBind();
}
注意别忘记在GridView中设置DataKeyNames一般是等于ID号(上面的topicList是GridView的ID号) --------------------编程问答-------------------- 不过你也可以设置自带分页功能,响应PageIndexChanging函数 --------------------编程问答-------------------- 自带分页
分页控件
自定义分页都可以 --------------------编程问答--------------------
http://www.webdiyer.com/controls/aspnetpager --------------------编程问答-------------------- 自己写一个分页控件吧 --------------------编程问答-------------------- jQuery + Table --------------------编程问答--------------------
大俠 你這個支持.net1.1麼? --------------------编程问答-------------------- aspnetpager,可以满足你的要求。 --------------------编程问答-------------------- 参考 --------------------编程问答--------------------
晕,现在还用.net 1.1?那只能在网上找4.5版以前的了,以后的版本是低支持.net2.0 --------------------编程问答--------------------
还是用着控件吧.
地址:http://www.webdiyer.com/controls/aspnetpager
补充:.NET技术 , ASP.NET