转到 GridView 分页功能中的特定页码

问题描述 投票:0回答:1

我试图通过允许用户在文本框中输入页码并单击文本为“GO”的按钮来实现“GO TO”页面。

.aspx 代码是;

<asp:Label ID="lblGoToPage" runat="server" Text="Go To Page : "></asp:Label>
<asp:TextBox ID="txtGoToPage" runat="server" Width="47px"></asp:TextBox>
<asp:Button ID="btnGo" runat="server" Text="Go" OnClick="btnGo_Click" />

并且 .cs 代码是;

protected void btnGo_Click(object sender, EventArgs e)
    {
        GridView1.PageIndex = Convert.ToInt16(txtGoToPage.Text);
        txtGoToPage.Text = "";
    }

上面的这些代码行给出了但不是所需的代码。无法弄清楚我哪里出了问题。任何帮助将不胜感激。预先感谢。

c# asp.net gridview pagination
1个回答
2
投票

更改页面索引后需要重新绑定网格。

protected void btnGo_Click(object sender, EventArgs e)
    {
        GridView1.PageIndex = Convert.ToInt16(txtGoToPage.Text) -1; //since PageIndex starts from 0 by default.
        txtGoToPage.Text = "";
        GridView1.DataBind()
    }
© www.soinside.com 2019 - 2024. All rights reserved.