• c#一个分页控件的例子


    一、首先下载一个dll,地址:http://pan.baidu.com/share/link?shareid=1628211605&uk=1342867987

    二、添加到项目中

    三、添加引用

    四、前台页面写法如下:

     

    复制代码
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <h3 style="color:Green;">品牌列表</h3>
            <div style="text-align:right;margin-bottom:5px;margin-right:35px;">
                <asp:Button ID="btnAdd" runat="server" Text="添加品牌" onclick="btnAdd_Click" />
            </div>
            <asp:DataGrid ID="DgBM" runat="server" HorizontalAlign="Center" Width="100%" AllowSorting="True"
                            AutoGenerateColumns="False" BorderStyle="None" GridLines="None" PageSize="2"
                            DataKeyField="id" OnItemCommand="DgBM_ItemCommand" OnItemDataBound="DgBM_ItemDataBound">
                            <AlternatingItemStyle ></AlternatingItemStyle>
                            <ItemStyle ></ItemStyle>
                            <HeaderStyle ></HeaderStyle>
                            <Columns>
                                <asp:BoundColumn DataField="BTitle" HeaderText="标题"></asp:BoundColumn>
                                <asp:BoundColumn DataField="Gtype" HeaderText="类型"></asp:BoundColumn>
                                <asp:BoundColumn DataField="createTime" HeaderText="创建时间"></asp:BoundColumn>
                                <asp:BoundColumn DataField="Description" HeaderText="描述"></asp:BoundColumn>
                                <asp:TemplateColumn HeaderText="编辑" HeaderStyle-Width="60px">
                                    <ItemTemplate>
                                        <asp:ImageButton ID="Editimg" runat="server" CommandName="edit"
                                            ImageUrl="~/Images/work/edit.gif" AlternateText="编辑"></asp:ImageButton>
                                    </ItemTemplate>
                                    <EditItemTemplate>
                                        <asp:ImageButton ID="Saveimg" runat="server"  CommandName="save"
                                             AlternateText="保存"></asp:ImageButton>
                                        <asp:ImageButton ID="Closeimg" runat="server"  CommandName="close"
                                             AlternateText="取消"></asp:ImageButton>
                                    </EditItemTemplate>
                                </asp:TemplateColumn>
                                <asp:TemplateColumn HeaderText="删除" HeaderStyle-Width="60px">
                                    <ItemTemplate>
                                        <asp:ImageButton ID="Delimg" runat="server" CssClass="btn_op" CommandName="del" ImageUrl="~/images/work/del.gif">
                                        </asp:ImageButton>
                                    </ItemTemplate>
                                </asp:TemplateColumn>
                            </Columns>
                        </asp:DataGrid>
         <table cellspacing="0" cellpadding="0" width="95%">
                <tr>
                    <td>
                        <cc1:SqlPager ID="SqlPager1" runat="server" ControlToPaginate="DgBM" Height="30px"
                            BorderWidth="0px" BackColor="#FFFFFF" PagerStyle="ImageButtonNumericPageItems"
                            firstImg="../../images/work/first.gif" lastImg="../../images/work/last.gif" nextImg="../../images/work/next.gif"
                            prevImg="../../images/work/previous.gif" Width="100%" />
                        <br />
                    </td>
                </tr>
            </table>
        </div>
        </form>
    </body>
    </html>
    复制代码

     

    后台代码如下:

    复制代码
     protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                PageBind();
            }
        }
        #region 分页绑定列表
        /// <summary>
        /// 绑定通知公告列表
        /// </summary>
        public void PageBind()
        {
            string connStr = ConfigurationManager.AppSettings["DataConn"].ToString();
            string strCmd = "SELECT id,BTitle,(SELECT BTitle FROM BrandType WHERE id=Brand.BTID ) AS Gtype,createTime,imgURL,Description,sort FROM Brand";
            try
            {
                // 清除缓存      
                SqlPager1.ClearCache();
                // 绑定数据.
                SqlPager1.ConnectionString = connStr;
                SqlPager1.SelectCommand = strCmd;
                SqlPager1.SortField = "sort ASC";
                SqlPager1.ItemsPerPage = 20;
                SqlPager1.DataBind();
            }
            catch { }
        }
        #endregion
        protected void DgBM_ItemCommand(object source, DataGridCommandEventArgs e)
        {
    
        }
        protected void DgBM_ItemDataBound(object sender, DataGridItemEventArgs e)
        {
    
        }
        protected void btnAdd_Click(object sender, EventArgs e)
        {
    
        }
  • 相关阅读:
    网上订火车票,用chrome和firefox才是王道
    SYNOPSYS VCS常用命令使用详解
    archlinux failed retrieving file 'xxx'解决办法
    JQuery实现点击TreeView文本展开/折叠子节点
    解决VS2010下HTML5的无法智能提示的问题
    Win7 计算机右键“管理”失效
    virtualbox下安装archlinux
    Linux下修改(NTFS)磁盘(卷标)显示名称
    Win7下使用VMWare安装Archlinux
    1.XMLHttpRequest:
  • 原文地址:https://www.cnblogs.com/honghong75042/p/5773943.html
Copyright © 2020-2023  润新知