asp.net gridview 分页

GRIDVIEW 自带的分页模式只有四种,当要实现NUMERIC和PREVIOUS与NEXT混合模式时,就需要自己定义PAGETEMPLATE。

CODE:

<PagerTemplate>
            <asp:LinkButton ID="lnkPreviousPage" runat="server" Text="上一页" CommandName="PreviousPage" />
            <asp:LinkButton ID="lnkPage1" runat="server" Text="1" CommandName="PageNumber" CommandArgument="1" />
            <asp:LinkButton ID="lnkPage2" runat="server" Text="2" CommandName="PageNumber" CommandArgument="2"/>
            <asp:LinkButton ID="lnkPage3" runat="server" Text="3" CommandName="PageNumber" CommandArgument="3"/>
            <asp:LinkButton ID="lnkPage4" runat="server" Text="4" CommandName="PageNumber" CommandArgument="4"/>
            <asp:LinkButton ID="lnkPage5" runat="server" Text="5" CommandName="PageNumber" CommandArgument="5"/>
            <asp:LinkButton ID="lnkPage6" runat="server" Text="6" CommandName="PageNumber" CommandArgument="6"/>
            <asp:LinkButton ID="LnkPage7" runat="server" Text="7" CommandName="PageNumber" CommandArgument="7"/>
            <asp:LinkButton ID="LnkPage8" runat="server" Text="8" CommandName="PageNumber" CommandArgument="8"/>
            <asp:LinkButton ID="LnkPage9" runat="server" Text="9" CommandName="PageNumber" CommandArgument="9"/>
            <asp:LinkButton ID="LnkPage10" runat="server" Text="10" CommandName="PageNumber" CommandArgument="10" />
            <asp:LinkButton ID="lnkNextPage" runat="server" Text="下一页" CommandName="NextPage" />
            </PagerTemplate>


这里HARDCODE了10页和两个按钮:上一页,下一页。

 

CODE BEHIND:

数据绑定事件:

 protected void grdMeetingList_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            switch (e.CommandName)
            {
                case "deleteMeeting":
                    DeleteGridViewMeetingById(Utility.ConvertToString(e.CommandArgument));
                    break;
                case "stopMeeting":
                    StopGridViewMeetingById(Utility.ConvertToString(e.CommandArgument));
                    break;
                case "editMeeting":
                    RedirectToMeetingPage(Utility.ConvertToString(e.CommandArgument.ToString()));
                    break;
                case "lenthenMeeting":
                    RedirectToMeetingPage(Utility.ConvertToString(e.CommandArgument.ToString()));
                    break;
                case "showMeetingDetail":
                    RedirectToMeetingPage(Utility.ConvertToString(e.CommandArgument.ToString()));
                    break;
                case "PreviousPage":
                    grdMeetingList.PageIndex = grdMeetingList.PageIndex > 0 ? grdMeetingList.PageIndex - 1 : grdMeetingList.PageIndex;
                    SearchMeeting();
                    break;
                case "NextPage":
                    grdMeetingList.PageIndex = grdMeetingList.PageIndex < grdMeetingList.PageCount ? grdMeetingList.PageIndex + 1 : grdMeetingList.PageIndex;
                    SearchMeeting();
                    break;
                case "PageNumber":
                    int? pageNum = Utility.ConvertToInt(e.CommandArgument,0);
                    grdMeetingList.PageIndex = pageNum.HasValue ? pageNum.Value : 0;
                    SearchMeeting();
                    break;
                default:
                    break;
            }
        }


你可能感兴趣的:(object,server,asp.net,asp)