日期:2014-05-16  浏览次数:20580 次

[ExtNet] GridPanel怎么实现服务器端分页、排序、查询?--Oracel存储过程分页

A.前端aspx文件

i.store定义
    <ext:Store ID="StoreIma" runat="server" OnRefreshData="StoreIma_OnRefreshData">
        <Reader>
            <ext:JsonReader>
                <Fields>
                    <ext:RecordField Name="ID" Mapping="ID" Type="String" />
                    <ext:RecordField Name="RANDOM_STRING" Mapping="RANDOM_STRING" Type="String" />
                </Fields>
            </ext:JsonReader>
        </Reader>
        <Proxy>
            <ext:PageProxy>

            </ext:PageProxy>
        </Proxy>
    </ext:Store>
 ii.Gridpanel定义
    <ext:GridPanel ID="GpItem" runat="server" Width="1024" Height="500" StripeRows="true" StoreID="StoreIma">
        <ColumnModel ID="ColumnModel1" runat="server">
            <Columns>
                <ext:Column Header="ID号" DataIndex="ID" Width="120">
                </ext:Column>
                <ext:Column Header="RANDOM_STRING" DataIndex="RANDOM_STRING" Width="320">
                </ext:Column>
            </Columns>
        </ColumnModel>
        <SelectionModel>
            <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" />
        </SelectionModel>
        <LoadMask ShowMask="true" />
        <BottomBar>
            <ext:PagingToolbar ID="PagingToolBar1" StoreID="StoreIma" PageSize="100" runat="server" />
        </BottomBar>
    </ext:GridPanel>

B.后端aspx.cs文件

protected void StoreIma_OnRefreshData(object sender, StoreRefreshDataEventArgs e)
        {
            int PageSize = this.PagingToolBar1.PageSize; //获取当前在页面中PagingToolBar 的PageSize的值
            int Count = 0;
            int CurPage = e.Start / PageSize + 1; //获取当前的页码是多少,也就是第几页
            var store = this.GpItem.GetStore();

            Model.PageBar page = new Model.PageBar();
            page.Tables = "myTestTable";
            page.Filter = "  1=1 ";
            page.PrimaryKey = "ID";
            page.Sort = "ASC";
            page.CurrentPage = CurPage;
            page.PageSize =PageSize;
            page.Fields = "ID,RANDOM_STRING";

            DataTable dt = GetListByPage(page); //连接数据库
            e.Total = page.Count;
            //this.PagingToolBar1.DisplayMsg = CurPage + " - " + PageSize + "页 共 " + e.Total + " 条";
            if (page.Count > 0)
            {
                store.DataSource = dt;//绑定数据
                store.DataBind();
            }
            else
            {
                X.Msg.Alert("查询结果", "<font style='color:red;'>没有找到任何数据!</font>").Show();
            }

        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        /// <param name="model">分页实体对象</param>
        /// <returns>数据列表</returns>
        public DataTable GetListByPage(Model.PageBar model)
        {
            OracleParameter[] parameters = {
                    new OracleParameter("p_tableName", OracleType.NVarChar),//名字
                    new OracleParameter("p_strWhere", OracleType.NVarChar),//查询条件(注意: 不要加 where)
                    new OracleParameter("p_orderColumn", OracleType.NVarChar),//排序字段
                    new OracleParameter("p_orderStyle", OracleType.NVarChar), //排序类型