gridview 中的分页

发布于 2024-11-13 07:54:36 字数 1926 浏览 4 评论 0原文

我的 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>

和我的代码隐藏:

    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();
    }

并且“分页”不起作用。它显示前 5 行,但不显示分页数

这是什么问题???

请帮忙

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

似最初 2024-11-20 07:54:36

尝试在 GridView 标记中添加一些寻呼机设置

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

如果有效,您可以将其更改为您想要的外观。有许多选择,包括

  • FirstPageImageUrl
  • FirstPageText
  • LastPageImageUrl
  • LastPageText
  • 模式(例如数字或
    NumericFirstLast)
  • NextPageImageUrl
  • NextPageText
  • PageButtonCount
  • 位置
  • PreviousPageImageUrl
  • PreviousPageText
  • 可见`

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`
So要识趣 2024-11-20 07:54:36

添加 PagerSettings-GridView-Markup 的属性并将其设置为 True

PagerSettings-Visible="true"

编辑:但默认情况下应该为 true,所以我不确定这是否会改变什么

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

伴随着你 2024-11-20 07:54:36
 Use **"PageIndexChanged"**

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

protected void gridView1_PageIndexChanged(object sender, GridViewPageEventArgs e)
        {
            try
            {
                gridView1.PageIndex = e.NewPageIndex;
                BindDataGrid();
    ;
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文