Paging in gridview

和自甴很熟 提交于 2019-12-24 03:05:31

问题


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


回答1:


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`



回答2:


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




回答3:


 Use **"PageIndexChanged"**

protected void gridView1_PageIndexChanged(object sender, GridViewPageEventArgs e)
        {
            try
            {
                gridView1.PageIndex = e.NewPageIndex;
                BindDataGrid();
    ;
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
        }


来源:https://stackoverflow.com/questions/6224998/paging-in-gridview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!