Page分页

前台代码

 <table border="0" align="right" cellpadding="0" cellspacing="0">
        <tr>
          <td style="background-image:url('../images/Repeater/bg.gif'); background-color:#FFFFFF" width="40"><asp:ImageButton ID="ImageButtonfirst"
                  ImageUrl="../images/Repeater/first.gif" runat="server"
                  οnclick="ImageButtonfirst_Click" /></td>
          <td style="background-image:url('../images/Repeater/bg.gif'); background-color:#FFFFFF" width="45"><asp:ImageButton ID="ImageButtonback"
                  ImageUrl="../images/Repeater/back.gif"  runat="server"
                  οnclick="ImageButtonback_Click"/></td>
          <td style="background-image:url('../images/Repeater/bg.gif'); background-color:#FFFFFF" width="45"><asp:ImageButton ID="ImageButtonnext"
                  ImageUrl="../images/Repeater/next.gif"  runat="server"
                  οnclick="ImageButtonnext_Click"/></td>
          <td style="background-image:url('../images/Repeater/bg.gif'); background-color:#FFFFFF" width="40"><asp:ImageButton ID="ImageButtonlast"
                  ImageUrl="../images/Repeater/last.gif"  runat="server"
                  οnclick="ImageButtonlast_Click"/></td>
          <td style="background-image:url('../images/Repeater/bg.gif'); background-color:#FFFFFF" width="100"><div align="center">转到第
            <asp:dropdownlist id="DDLPage" runat="server" Width="40px" AutoPostBack="True"
                  onselectedindexchanged="DDLPage_SelectedIndexChanged">
            </asp:dropdownlist>
            页 </div></td>
        </tr>
    </table>

 

 

//后台代码

 

namespace ExpenseRecord.userControl
{
    public partial class WebForm12 : System.Web.UI.Page
    {
        public int recordCount = 0;

        protected void Page_Load(object sender, EventArgs e)
        {

            if (!(ViewState["recordCount"] is DBNull))
            {
                recordCount = Convert.ToInt32(ViewState["recordCount"]);
            }

            if (!Page.IsPostBack)
            {
                this.lkDeleteAll.Attributes.Add("onclick", "return window.confirm('您确定要删除您选中的“消费资料”吗?')");
                this.rptDataBind();
            }
        }

        #region 分页控件
        private void rptDataBind()
        {
            DataSet ds = ExpenDetailBLL.GetList("where UserId=" + SessionInclude.SessionId + " order by ShopTime desc ");
            recordCount = ds.Tables[0].Rows.Count;

            ViewState["recordCount"] = recordCount;

            //分页控件设置
            PagedDataSource pds = new PagedDataSource();
            pds.DataSource = ds.Tables[0].DefaultView;
            pds.AllowPaging = true;         //是否启用分页
            pds.PageSize = 3;               //每页显示的行数
            pds.CurrentPageIndex = Convert.ToInt32(this.labpage.Text) - 1;  //获取当前页的索引

            //绑定数据
            this.rptExpInfo.DataSource = pds;

            //初始化分页数据
            this.labCount.Text = ds.Tables[0].Rows.Count.ToString();
            labcountpage.Text = pds.PageCount.ToString();   //总页数
            labpage.Text = (pds.CurrentPageIndex + 1).ToString();   //当前页
            this.ImageButtonfirst.Enabled = true;
            this.ImageButtonfirst.ImageUrl = "../images/Repeater/first.gif";
            this.ImageButtonback.Enabled = true;
            this.ImageButtonback.ImageUrl = "../images/Repeater/back.gif";
            this.ImageButtonnext.Enabled = true;
            this.ImageButtonnext.ImageUrl = "../images/Repeater/next.gif";
            this.ImageButtonlast.Enabled = true;
            this.ImageButtonlast.ImageUrl = "../images/Repeater/last.gif";

            if (pds.CurrentPageIndex < 1)
            {
                this.ImageButtonfirst.Enabled = false;
                this.ImageButtonfirst.ImageUrl = "../images/Repeater/first.jpg";
                this.ImageButtonback.Enabled = false;
                this.ImageButtonback.ImageUrl = "../images/Repeater/back.jpg";
            }

            if (pds.CurrentPageIndex == pds.PageCount - 1)
            {
                this.ImageButtonnext.Enabled = false;
                this.ImageButtonnext.ImageUrl = "../images/Repeater/next.jpg";
                this.ImageButtonlast.Enabled = false;
                this.ImageButtonlast.ImageUrl = "../images/Repeater/last.jpg";
            }

            //跳转
            DDLPage.Items.Clear();

            for (int i = 1; i <= pds.PageCount; i++)
            {
                DDLPage.Items.Add(new ListItem(i.ToString(), i.ToString()));
            }

            this.rptExpInfo.DataBind();
        }

        //首页
        protected void ImageButtonfirst_Click(object sender, ImageClickEventArgs e)
        {
            this.labpage.Text = "1";
            this.rptDataBind();
        }

        //上一页
        protected void ImageButtonback_Click(object sender, ImageClickEventArgs e)
        {
            this.labpage.Text = Convert.ToString(Convert.ToInt32(this.labpage.Text) - 1);
            this.rptDataBind();
        }

        //下一页
        protected void ImageButtonnext_Click(object sender, ImageClickEventArgs e)
        {
            this.labpage.Text = Convert.ToString(Convert.ToInt32(this.labpage.Text) + 1);
            this.rptDataBind();
        }

        //尾页
        protected void ImageButtonlast_Click(object sender, ImageClickEventArgs e)
        {
            this.labpage.Text = this.labcountpage.Text;
            this.rptDataBind();
        }

        //跳转页面
        protected void DDLPage_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.labpage.Text = this.DDLPage.SelectedValue.ToString();
            this.rptDataBind();

            //设置DropDownList1的默认值(上一级菜单)
            foreach (ListItem item in DDLPage.Items)
            {
                if (item.Value == labpage.Text.ToString())
                {
                    item.Selected = true;
                }
            }
        }
        #endregion

        #region 绑定消费资料
        /// <summary>
        /// 绑定消费资料
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void rptExpInfo_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                //Label lblExpType = (Label)e.Item.FindControl("lblExpType");

                LinkButton lkDelete = (LinkButton)e.Item.FindControl("lkDelete");

                DataRowView drv = (DataRowView)e.Item.DataItem;

                string ExpType = drv["ExpType"].ToString();

                Image imgExpType = (Image)e.Item.FindControl("imgExpType");

                if (ExpType == "0")
                {
                    imgExpType.ImageUrl = "../images/mark2.gif";
                    imgExpType.ToolTip = "生活资料消费";

                    lkDelete.Attributes.Add("onclick", "return window.confirm('您确定要删除[生活资料消费]“" + drv["ExpName"].ToString() + "”吗?');");
                }
                else if (ExpType == "1")
                {
                    imgExpType.ImageUrl = "../images/mark1.gif";
                    imgExpType.ToolTip = "高级资料消费";
                    lkDelete.Attributes.Add("onclick", "return window.confirm('您确定要删除[高级资料消费]“" + drv["ExpName"].ToString() + "”吗?');");
                }
                else
                {
                    imgExpType.ImageUrl = "../images/mark3.gif";
                    imgExpType.ToolTip = "其它资料消费";
                    lkDelete.Attributes.Add("onclick", "return window.confirm('您确定要删除[其它资料消费]“" + drv["ExpName"].ToString() + "”吗?');");
                }

                //OnClientClick='return OpenModel("<%# Eval("ExpID") %>");'

                #region 弹出模态窗体

                LinkButton lkbExpID = (LinkButton)e.Item.FindControl("lkDetail");

                 lkbExpID.Attributes.Add("onclick", "return showModalDialog('ExpenseDetail.aspx?ExpId=" + drv["ExpId"].ToString() + "','subpage','dialogWidth:700px;dialogHeight:340px;center:yes;help:no;resizable:no;status:no');");
                #endregion
            }
        }
        #endregion

        #region 全部选择和取消选择
        /// <summary>
        /// 全部选择和取消选择
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ckChooseAll_CheckedChanged(object sender, EventArgs e)
        {
            if (this.ckChooseAll.Checked == true)
            {
                foreach (RepeaterItem item in this.rptExpInfo.Items)
                {
                    if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
                    {
                        CheckBox ckChoose = (CheckBox)item.FindControl("ckChoose");
                        ckChoose.Checked = true;
                    }
                }
            }
            else
            {
                foreach (RepeaterItem item in this.rptExpInfo.Items)
                {
                    if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
                    {
                        CheckBox ckChoose = (CheckBox)item.FindControl("ckChoose");
                        ckChoose.Checked = false;
                    }
                }
            }

            recordCount = Convert.ToInt32(ViewState["recordCount"]);
        }
        #endregion

    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值