<dxwgv:ASPxGridView

HtmL

<dxwgv:ASPxGridView ID="dxgvGrid" runat="server" ClientInstanceName="dxgvGrid" AutoGenerateColumns="False" KeyFieldName="PERSON_ID" oncustomcallback="dxgvGrid_CustomCallback" >

<Settings ShowStatusBar="Visible" />
                            <SettingsPager Visible="false">
                            </SettingsPager>
                            <Templates>
                                <StatusBar>
                                    <div style="text-align: right;">
                                        每頁記錄數:
                                        <select onchange="dxgvGrid.PerformCallback(this.value);">
                                            <option value="5" <%# WriteSelectedIndex(5) %>>5</option>
                                            <option value="10" <%# WriteSelectedIndex(10) %>>10</option>
                                            <option value="20" <%# WriteSelectedIndex(15) %>>20</option>
                                            <option value="50" <%# WriteSelectedIndex(20) %>>50</option>
                                            <option value="100" <%# WriteSelectedIndex(25) %>>100</option>
                                        </select>
                                        <%#GetShowingOnPage() %>&nbsp; <a title="第一頁" href="JavaScript:dxgvGrid.GotoPage(0);">
                                            &lt;&lt;</a> &nbsp; <a title="上一頁" href="JavaScript:dxgvGrid.PrevPage();">&lt;</a>
                                        &nbsp; 頁
                                        <input type="text" onchange="dxgvGrid.GotoPage(parseInt(this.value, 10) - 1)"
                                            onkeydown="if (event.keyCode == 13) { event.cancelBubble=true; event.returnValue = false; dxgvGrid.GotoPage(parseInt(this.value, 10) - 1); return false; }"
                                            value="<%# dxgvGrid.PageIndex + 1 %>" style="width: 20px" />
                                        of
                                        <%# dxgvGrid.PageCount%>
                                        &nbsp; <a title="下一頁" href="JavaScript:dxgvGrid.NextPage();">&gt;</a> &nbsp;
                                        <a title="最後一頁" href="JavaScript:dxgvGrid.GotoPage(<%# dxgvGrid.PageCount - 1 %>);">
                                            &gt;&gt;</a> &nbsp;
                                    </div>
                                </StatusBar>
                            </Templates>

.cs

#region 分頁操作
    protected void dxgvGrid_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e)
    {
        int newPageSize;
        if (!int.TryParse(e.Parameters, out newPageSize)) return;
        dxgvGrid.SettingsPager.PageSize = newPageSize;
        Session[GridCustomPageSizeName] = newPageSize;
        dxgvGrid.DataBind();
    }

    protected string WriteSelectedIndex(int pageSize)
    {
        return pageSize == dxgvGrid.SettingsPager.PageSize ? "selected='selected'" : string.Empty;
    }
    protected string GetShowingOnPage()
    {
        int pageSize = dxgvGrid.SettingsPager.PageSize;
        int startIndex = dxgvGrid.PageIndex * pageSize + 1;
        int endIndex = (dxgvGrid.PageIndex + 1) * pageSize;
        if (endIndex > dxgvGrid.VisibleRowCount)
        {
            endIndex = dxgvGrid.VisibleRowCount;
        }
        return string.Format("當前記錄 {0}-{1} of {2}", startIndex, endIndex, dxgvGrid.VisibleRowCount);
    }
    #endregion

posted @ 2012-12-10 10:50  rongnianwu  阅读(331)  评论(0编辑  收藏  举报