Reputation:
I am trying to implement GO TO page by allowing the user to enter page number in a text box and clicking a button texted as GO.
.aspx code is;
<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" />
and .cs code is;
protected void btnGo_Click(object sender, EventArgs e)
{
GridView1.PageIndex = Convert.ToInt16(txtGoToPage.Text);
txtGoToPage.Text = "";
}
These above lines of code are giving out but not the desired one. Cant figure out where I am going wrong. Any help will be much appreciated. Thanks in advance.
Upvotes: 1
Views: 6562
Reputation: 55434
You need to rebind the grid after you change the page index.
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()
}
Upvotes: 2