【问题标题】:Going to a specific page number in a GridView paging feature转到 GridView 分页功能中的特定页码
【发布时间】:2013-09-09 18:20:58
【问题描述】:

我正在尝试通过允许用户在文本框中输入页码并单击文本为 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 paging


    【解决方案1】:

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

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

    【讨论】:

    • 非常感谢您的及时帮助。真的很感激。您的解决方案就像一个魅力。只做了一点点编辑。谢谢大家。
    猜你喜欢
    • 1970-01-01
    • 2019-02-24
    • 1970-01-01
    • 1970-01-01
    • 2014-02-24
    • 2014-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多