天天看點

ASPxGridview自定義分頁

<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();
    }