自定义分页
来源:互联网 发布:罗技游戏鼠标 知乎 编辑:程序博客网 时间:2024/05/16 11:06
前台: <tr> 后台: 数据绑定:private void GridView_Bind() PagedDataSource ps = new PagedDataSource();//生成PageDataSource的实例用于分页 事件: /// <summary> /// <summary> /// <summary> /// <summary> 初始化: if (!IsPostBack)
<td align="center">
<asp:Panel ID="Panel3" runat="server" style="margin-left: 0px" Width="60%"
BackColor="#507CD1" Height="19px">
<table style="height: 21px">
<tr>
<td valign="middle">
<asp:LinkButton ID="LinkButton2" runat="server" onclick="LinkButton2_Click" ForeColor="White"
>首页</asp:LinkButton>
<asp:LinkButton ID="LinkButton3" runat="server"
onclick="LinkButton3_Click" ForeColor="White" >上一页</asp:LinkButton>
<asp:LinkButton ID="LinkButton4" runat="server"
onclick="LinkButton4_Click" ForeColor="White" >下一页</asp:LinkButton>
<asp:LinkButton ID="LinkButton5" runat="server" onclick="LinkButton5_Click" ForeColor="White"
>尾页</asp:LinkButton>
<asp:Label ID="Label4" runat="server" CssClass="label_style" ForeColor="White"></asp:Label>
<asp:Label ID="Label5" runat="server" CssClass="label_style" ForeColor="White"></asp:Label>
<asp:Label ID="Label6" runat="server" CssClass="label_style" ForeColor="White"></asp:Label>
</td>
</tr>
</table>
</asp:Panel>
</td>
</tr>
{
string title = TextBox1.Text;
string sql = "select a.Title,b.AwordName,c.Itemid,c.Userid,c.Score,c.Flag from X186_SecKillActivity as a,X186_ActiviryAword as b,X186_ActivityResult as c where a.Id=c.Aid and c.AwordID=b.Awordid";
if (title != "")
{
sql += " and a.Title like '%" + title + "%'";
}
sql += " order by c.Aid,c.Itemid,c.Score";
DataTable dt = DataAccess.GetDataTable(sql);
ps.DataSource = dt.DefaultView;
ps.AllowPaging = true;
ps.PageSize = 8;
int CurrentPage = Convert.ToInt32(Label4.Text);
ps.CurrentPageIndex = CurrentPage - 1;
if (ps.PageCount <= 1)
{
this.Panel3.Visible = false;
}
else
{
this.Panel3.Visible = true;
if (CurrentPage == 1)
{
LinkButton2.Enabled = false;
LinkButton3.Enabled = false;
LinkButton4.Enabled = true;
LinkButton5.Enabled = true;
}
if (CurrentPage == ps.PageCount)
{
LinkButton2.Enabled = true;
LinkButton3.Enabled = true;
LinkButton4.Enabled = false;
LinkButton5.Enabled = false;
}
if (CurrentPage > 1 && CurrentPage < ps.PageCount)
{
LinkButton2.Enabled = true;
LinkButton3.Enabled = true;
LinkButton4.Enabled = true;
LinkButton5.Enabled = true;
}
Label5.Text = Convert.ToString(ps.PageCount);
Label6.Text = Label4.Text + "/" + Label5.Text + "页";
}
this.GridView1.DataSource = ps;
this.GridView1.DataBind();
}
/// 首页
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void LinkButton2_Click(object sender, EventArgs e)
{
Label4.Text = "1";
GridView_Bind();
}
/// 上一页
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void LinkButton3_Click(object sender, EventArgs e)
{
Label4.Text = Convert.ToString(Convert.ToInt32(Label4.Text) - 1);
GridView_Bind();
}
/// 下一页
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void LinkButton4_Click(object sender, EventArgs e)
{
Label4.Text = Convert.ToString(Convert.ToInt32(Label4.Text) + 1);
GridView_Bind();
}
/// 尾页
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void LinkButton5_Click(object sender, EventArgs e)
{
Label4.Text = Label5.Text;
GridView_Bind();
}
{
this.Label4.Text = "1";
this.Label4.Visible = false;
this.Label5.Visible = false;
GridView_Bind();
}
- 自定义分页
- 自定义分页
- 自定义分页
- 自定义分页
- 自定义分页
- 自定义分页
- 自定义分页
- 自定义分页
- 自定义分页
- 自定义分页
- 自定义分页
- 自定义分页
- 自定义分页
- 自定义分页
- 分页:高度自定义分页
- yii2自定义分页分页属性
- 自定义DataGrid分页设置
- [转]DataGrid自定义分页
- memcached源码阅读
- Symbian——解析XML文件
- 分布式 DBA:DB2 深度压缩
- OpenGL材质和光照(转)part1
- 编程与女人的关系
- 自定义分页
- 实例对比Oracle中truncate和delete的区别
- Convert.ToInt32与Int32.Parse的恩恩怨怨
- 机器学习的牛人们_遥远的星空
- Split的3种用法
- Solaris 进程 heap段内存释放小研
- 整合Flex+struts+BlazeDS+tomcat+mysql
- url传递中文的解决方案
- 阿基米德反证法