Paging in gridview

2019-07-16 18:48发布

My gridView:

              <asp:GridView ID="gridView1" runat="server" CellPadding="4" AllowPaging="true" PageSize="5"  emptydatatext="No data available." 
                    CssClass="datagrid" 
                    ForeColor="#333333" GridLines="None" 
                    onrowcreated="gridView1_RowCreated" 
                    onpageindexchanging="gridView1_PageIndexChanging">

                    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                    <EditRowStyle BackColor="#999999" />
                    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                    <SortedAscendingCellStyle BackColor="#E9E7E2" />
                    <SortedAscendingHeaderStyle BackColor="#506C8C" />
                    <SortedDescendingCellStyle BackColor="#FFFDF8" />
                    <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
                </asp:GridView>

And my codebehind:

    protected void gridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gridView1.PageIndex = e.NewPageIndex;
        BindDataGrid();
    }



    protected void BindDataGrid()
    {

        DataSet ds = new DataSet();

        ds = dbM.GetInfo(name, mobilePhone, info1); //get info to BD and save in "ds"

        gridView1.DataSource = ds;
        gridView1.DataBind();
    }

and the "Paging" does not work. It shows the first 5 rows, but does not show the number of paging

What´s wrong???

Please help

thanks

3条回答
兄弟一词,经得起流年.
2楼-- · 2019-07-16 19:22

Try adding some pager settings in the GridView tag:

<PagerSettings Mode="NextPreviousFirstLast" Position="TopAndBottom" />

If that works, you can change it to your desired appearance. There are many choices, including

  • FirstPageImageUrl
  • FirstPageText
  • LastPageImageUrl
  • LastPageText
  • Mode (such as Numeric or NumericFirstLast)
  • NextPageImageUrl
  • NextPageText
  • PageButtonCount
  • Position
  • PreviousPageImageUrl
  • PreviousPageText
  • Visible`
查看更多
ゆ 、 Hurt°
3楼-- · 2019-07-16 19:25

Add the PagerSettings-Property to the GridView-Markup and set it to True:

PagerSettings-Visible="true"

Edit: but it should be true by default, so i'm not sure if this will change anything

查看更多
叛逆
4楼-- · 2019-07-16 19:46
 Use **"PageIndexChanged"**

protected void gridView1_PageIndexChanged(object sender, GridViewPageEventArgs e)
        {
            try
            {
                gridView1.PageIndex = e.NewPageIndex;
                BindDataGrid();
    ;
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
        }
查看更多
登录 后发表回答