zoukankan      html  css  js  c++  java
  • Repeater 数据绑定 分页

      最近有使用到repeater来做数据绑定查询,是用来记录后台校验数据错误记录的临时查询。因为原先使用的都是从数据库中直接读表方式绑定,同时项目中有写好的分页控件,这次因为使用自定义错误记录并显示,不再将错误写到数据库中的表里,然后再查询的样式,所以就搜索整理了下。

      (定义较为简单,有待完善)

      前台代码:

    <body>
        <form id="form1" runat="server">
        <div>
        <table class="repTable ">
            <asp:Repeater ID="dataTbe" runat="server">
                <HeaderTemplate>
                    <tr class="repHead">
                        <td scope="col" style=" 10%">
                            源数据来源
                        </td>
                        <td scope="col" style=" 8%">
                            标识号
                        </td>
                        <td scope="col" style=" 8%">
                            出错字段
                        </td>
                        <td scope="col" style=" 30%">
                            出错原因
                        </td>
                    </tr>
                </HeaderTemplate>
                <ItemTemplate>
                    <tr class="repItem">
                        <td scope="col" style=" 10%">
                            <%#Eval("DataSource")%>
                        </td>
                        <td scope="col" style=" 8%">
                            <%#Eval("IBSCLNO")%>
                        </td>
                        <td scope="col" style=" 8%">
                            <%#Eval("ErrField")%>
                        </td>
                        <td scope="col" style=" 30%">
                            <%#Eval("ErrDesc")%>  
                        </td>
                    </tr>
                </ItemTemplate>
            </asp:Repeater>
        </table>
        <asp:LinkButton ID="lbtnFirstPage" runat="server" OnClick="lbtnFirstPage_Click">页首</asp:LinkButton>  
                  <asp:LinkButton ID="lbtnpritPage" runat="server" OnClick="lbtnpritPage_Click">上一页</asp:LinkButton>   
                  <asp:LinkButton ID="lbtnNextPage" runat="server" OnClick="lbtnNextPage_Click">下一页</asp:LinkButton>  
                  <asp:LinkButton ID="lbtnDownPage" runat="server" OnClick="lbtnDownPage_Click">页尾</asp:LinkButton><br /><asp:Label ID="labPage" runat="server" Text="1"></asp:Label>页/共<asp:Label ID="LabCountPage" runat="server" Text="Label"></asp:Label></div>
        </form>
    </body>


    后台代码:

    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    
    public partial class SDNLMess_tESTY : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.labPage.Text = "1";
                DtBind();
            }
        }
    
        protected void DtBind(){
            DataTable datadt = new DataTable();
            datadt.Columns.Add(new DataColumn("DataSource")); //数据来源
            datadt.Columns.Add(new DataColumn("IBSCLNO"));  //主键
            datadt.Columns.Add(new DataColumn("ErrField")); //出错的字段
            datadt.Columns.Add(new DataColumn("ErrDesc")); //出错的原因
            datadt.Rows.Add(new object[4] { "临时", "123456", "yao", "断电" });//自定义写入dt中的数据(测试使用)
            datadt.Rows.Add(new object[4] { "临时", "123456", "yao", "断电" });
            datadt.Rows.Add(new object[4] { "临时", "123456", "yao", "断电" });
            datadt.Rows.Add(new object[4] { "临时", "123456", "yao", "断电" });
            datadt.Rows.Add(new object[4] { "临时", "123456", "yao", "断电" });
            datadt.Rows.Add(new object[4] { "临时", "123456", "yao", "断电" });
            datadt.Rows.Add(new object[4] { "临时", "123456", "yao", "断电" });
            datadt.Rows.Add(new object[4] { "临时", "123456", "yao", "断电" });
            datadt.Rows.Add(new object[4] { "临时", "123456", "yao", "断电" });
            //dataTbe.DataSource = datadt;
            //dataTbe.DataBind();
    
            PagedDataSource pds = new PagedDataSource();
            pds.DataSource = datadt.DefaultView;
            pds.AllowPaging = true;//启用分页
            pds.PageSize = 2;//设置每页显示条数
            pds.CurrentPageIndex = Convert.ToInt32(this.labPage.Text) - 1;//获取当前也索引
            dataTbe.DataSource = pds;//绑定数据源
            LabCountPage.Text = pds.PageCount.ToString();//得到页面总数
            labPage.Text = (pds.CurrentPageIndex + 1).ToString();//得到当前显示页面数
            this.lbtnpritPage.Enabled = true;//控制控件的显示与隐藏
            this.lbtnFirstPage.Enabled = true;
            this.lbtnNextPage.Enabled = true;
            this.lbtnDownPage.Enabled = true;
            if (pds.CurrentPageIndex + 1 == pds.PageCount)//当当前页为最后一页时控制下一页和尾页控件不可用
            {
                this.lbtnNextPage.Enabled = false;
                this.lbtnDownPage.Enabled = false;
            }
            if (labPage.Text == "1")//当当前页为第一页时控制第一页控件不可用
            {
                this.lbtnpritPage.Enabled = false;
            }
    
            dataTbe.DataBind();//repeater数据绑定
        }
    
        protected void lbtnpritPage_Click(object sender, EventArgs e)//上一页按钮事件
        {
            this.labPage.Text = Convert.ToString(Convert.ToInt32(labPage.Text) - 1);
            this.DtBind();
        }
    
        protected void lbtnFirstPage_Click(object sender, EventArgs e)//首页按钮事件
        {
    
            this.labPage.Text = "1";
    
            this.DtBind();
    
        }
    
    
    
        protected void lbtnDownPage_Click(object sender, EventArgs e)//下一页按钮事件
        {
    
            this.labPage.Text = this.LabCountPage.Text;
    
            this.DtBind();
    
        }
    
    
    
        protected void lbtnNextPage_Click(object sender, EventArgs e)//尾页事件
        {
    
            this.labPage.Text = Convert.ToString(Convert.ToInt32(labPage.Text) + 1);
    
            this.DtBind();
    
        }
        
    }
  • 相关阅读:
    日期时间格式或封装,已经互相转换,抽出来日后方便自己开发,之前用作在mpvue的框架开发小程序中
    微信小程序授权方法全能,当用户拒绝或者首次进来的,都可以弹起授权提示,主要是用wx.getSetting,还有wx.authorize,最后的wx.openSetting
    JavaScript封装自己的一个弹窗,是双按钮的,比较简单一些 ,其中引用了jQuery来写的方法,最后暴露出去,有更好的建议欢迎评论 。。。。
    最近学习mpvue框架开发微信小程序,把wepy框架的项目实现到mpvue中,知道其中的一些两者之间的区别
    JavaScript中历史搜索记录的实现,在h5页面,引用jQuery写法,使用localStorage存储
    vue中实现双向数据绑定原理,使用了Object.defineproperty()方法,方法简单
    好好学习vue中 写了一些demo 希望自己能提升多一点 vue中实现父子组件之间的通信 相比我的上一篇非父子组件会简单些
    Java中Scanner类在nextInt()后无法输入nextLine()的问题
    mybatis中#{}和${}的区别及order by的sql注入问题
    Intellij常用设置及快捷键
  • 原文地址:https://www.cnblogs.com/dreamskies/p/3448165.html
Copyright © 2011-2022 走看看