footleg

导航

GridView自身分页加跳转

<PagerTemplate>
<asp:LinkButton ID="lbFirst" runat="server" CausesValidation="False" CommandArgument="First"
CommandName="Page">首页 </asp:LinkButton>
<asp:LinkButton ID="lbPrev" runat="server" CausesValidation="False" CommandArgument="Prev"
CommandName="Page">上一页 </asp:LinkButton>
<asp:LinkButton ID="lbNext" runat="server" CausesValidation="False" CommandArgument="Next"
CommandName="Page">下一页 </asp:LinkButton>
<asp:LinkButton ID="lbLast" runat="server" CausesValidation="False" CommandArgument="Last"
CommandName="Page">尾页 </asp:LinkButton> 第 <asp:Label ID="Label2"
runat="server" Text=" <%#((GridView)Container.Parent.Parent).PageIndex + 1 %>"> </asp:Label>页
共 <asp:Label ID="Label1" runat="server" Text=" <%# ((GridView)Container.Parent.Parent).PageCount %>"> </asp:Label>页
跳到 <asp:TextBox ID="tbPage" runat="server" Text=" <%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>"
Width="27px"> </asp:TextBox>
<asp:LinkButton ID="lbGO" runat="server" CausesValidation="False" CommandArgument="-1"
CommandName="Page" Text="GO"> </asp:LinkButton>
</PagerTemplate>
CS代码:

 

//添加对lbGO单击事件
    protected void GoIndex(object sender, EventArgs e)
    {
        GridViewRow pagerRow = GridView1.BottomPagerRow;
        TextBox pageNum = pagerRow.Cells[0].FindControl("tbpage") as TextBox;
        if (pageNum.Text != null)
        {
            if (Convert.ToInt32(pageNum.Text) > 0 && Convert.ToInt32(pageNum.Text) <= GridView1.PageCount)
            GridView1.PageIndex = Convert.ToInt32(pageNum.Text) - 1;
        }
        this.BindToGridView();
    }

    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        if (e.NewPageIndex >= 0 && e.NewPageIndex < GridView1.PageCount)
        this.GridView1.PageIndex = e.NewPageIndex;
        this.BindToGridView();   //调用上面的BindToGridView()绑定
    }

 

posted on 2009-10-22 16:56  迷途  阅读(860)  评论(0编辑  收藏  举报