ASPxGridview自定义分页

来源:互联网 发布:java基本命名规范 编辑:程序博客网 时间:2024/06/08 15:31
<script  type="text/javascript">    //grid自定义翻页    var CustomPager = {        gotoBox_Init: function (s, e) {            s.SetText(1 + grid.GetPageIndex());            adjustSize();                   },        gotoBox_KeyPress: function (s, e) {            if (e.htmlEvent.keyCode != 13)                return;            CustomPager.applyGotoBoxValue(s);        },        gotoBox_ValueChanged: function (s, e) {            CustomPager.applyGotoBoxValue(s);        },        applyGotoBoxValue: function (textBox) {            var pageIndex = parseInt(textBox.GetText()) - 1;            if (pageIndex < 0)                pageIndex = 0;            grid.GotoPage(pageIndex);        },        combo_SelectedIndexChanged: function(s, e) {            grid.PerformCallback(s.GetSelectedItem().text);        }    };    function adjustSize() {        var height = Math.max(0, (window.screen.availHeight * 1.0 - 320));        grid.SetHeight(height);    }</scipt><Templates>                <PagerBar>                                        <table>                        <tr>                            <td>                                <dx:ASPxButton runat="server" ID="FirstButton" Text="第一页" Enabled="<%# Container.Grid.PageIndex > 0 %>"                                    AutoPostBack="false" Width="60px">                                    <ClientSideEvents Click="function() { grid.GotoPage(0) }" />                                </dx:ASPxButton>                            </td>                            <td>                                <dx:ASPxButton runat="server" ID="PrevButton" Text="上一页" Enabled="<%# Container.Grid.PageIndex > 0 %>"                                    AutoPostBack="false" Width="60px">                                    <ClientSideEvents Click="function() { grid.PrevPage() }" />                                </dx:ASPxButton>                            </td>                            <td>                                <dx:ASPxTextBox runat="server" ID="GotoBox" Width="30">                                    <ClientSideEvents Init="CustomPager.gotoBox_Init" ValueChanged="CustomPager.gotoBox_ValueChanged" />                                </dx:ASPxTextBox>                            </td>                            <td>                                <span style="white-space: nowrap">of                                    <%# Container.Grid.PageCount %>                                </span>                            </td>                            <td>                                <dx:ASPxButton runat="server" ID="NextButton" Text="下一页" Enabled="<%# Container.Grid.PageIndex < Container.Grid.PageCount - 1 %>"                                    AutoPostBack="false" Width="60px">                                    <ClientSideEvents Click="function() { grid.NextPage() }" />                                </dx:ASPxButton>                            </td>                            <td>                                <dx:ASPxButton runat="server" ID="LastButton" Text="最后一页" Enabled="<%# Container.Grid.PageIndex < Container.Grid.PageCount - 1 %>"                                    AutoPostBack="false" Width="75px">                                    <ClientSideEvents Click="function() { grid.GotoPage(grid.GetPageCount() - 1); }" />                                </dx:ASPxButton>                            </td>                            <td>                                <span style="white-space: nowrap">共<%#Container.Grid.VisibleRowCount %>条数据</span>                            </td>                            <td style="width:100%; ">                                <div style="width: 75px; float: right">                                    <dx:ASPxButton ID="ASPxButton2" OnClick="ASPxButton2_Click" runat="server" Text="导 出" Image-Url="~/Images/16icon/filesave.png"></dx:ASPxButton>                                </div>                            </td>                             <td style="white-space: nowrap">                            <span style="white-space: nowrap">                                每页显示条数:                            </span>                        </td>                        <td>                            <dx:ASPxComboBox runat="server" ID="Combo" Width="50" DropDownWidth="50" ValueType="System.Int32"                                OnLoad="PagerCombo_Load">                                <Items>                                    <dx:ListEditItem Value="8" />                                    <dx:ListEditItem Value="10" />                                    <dx:ListEditItem Value="15" />                                </Items>                                <ClientSideEvents SelectedIndexChanged="CustomPager.combo_SelectedIndexChanged" />                            </dx:ASPxComboBox>                        </td>                        </tr>                    </table>                </PagerBar></Templates>protected void PagerCombo_Load(object sender, EventArgs e)    {        (sender as ASPxComboBox).Value = this.ASPxGridView1.SettingsPager.PageSize;    }protected int GridPageSize    {        get        {            if (Session[PageSizeSessionKey] == null)                return ASPxGridView1.SettingsPager.PageSize;            return (int)Session[PageSizeSessionKey];        }        set { Session[PageSizeSessionKey] = value; }    }protected void Page_Init(object sender, EventArgs e)    {        ASPxGridView1.SettingsPager.PageSize = GridPageSize;    }protected void ASPxGridView1_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e)    {        GridPageSize = int.Parse(e.Parameters);        //ASPxGridView1.SettingsPager.PageSize = GridPageSize;        Page_Init(sender,e);        ASPxGridView1.DataBind();    }

0 0