我正在尝试实现GO TO page.Means当我在文本框中输入任何页码时#34; txtGoToPage"然后单击按钮" btnGo"它应该带我到那个页面。
<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" />
<asp:GridView ID="gv" runat="server" AutoGenerateColumns="false" OnRowDataBound="gv_RowDataBound" OnRowDeleting="gv_RowDeleting" OnRowEditing="gv_RowEditing" CellPadding="4" ForeColor="#333333" OnRowCreated="gv_RowCreated" OnRowCommand="gv_RowCommand" OnRowUpdating="gv_RowUpdating" AllowPaging="true" OnPageIndexChanging="gv_PageIndexChanging" GridLines="Both" CssClass="GridViewStyle" class="ui-widget-content" Style="width: 100%; padding: 2px" OnSelectedIndexChanged="gv_SelectedIndexChanged">
<EditRowStyle CssClass="GridViewEditRow" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<PagerStyle CssClass="pager" />
<Columns>
<asp:TemplateField Visible="false" HeaderText="ID">
<ItemTemplate>
<asp:Label ID="lblID" runat="server" Text='<%#Eval("id") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Correct">
<ItemTemplate>
<asp:Label ID="lblCorrect" runat="server" Text='<%#Eval("correct") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtCorrect" runat="server" Width="40px" Text='<%#Eval("correct") %>' />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Comments">
<ItemTemplate>
<asp:Label ID="lblComments" runat="server" Text='<%#Eval("comments") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtComments" runat="server" TextMode="multiline" Width="50px" Columns="50" Rows="5" Text='<%#Eval("comments") %>' />
</EditItemTemplate>
</asp:TemplateField>
</Columns>
<PagerSettings FirstPageText="First" LastPageText="Last"
Mode="Numeric" PageButtonCount="20" PreviousPageText="Previous" />
</asp:GridView>
提前致谢。
答案 0 :(得分:0)
示例答案:
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()
}