<PagerTemplate>
<asp:LinkButton ID="LinkButtonFirstPage" runat="server" CommandArgument="First" CommandName="Page" Enabled=" <%# ((GridView)Container.NamingContainer).PageIndex != 0 %>">首页</asp:LinkButton>
<asp:LinkButton ID="LinkButtonPreviousPage" runat="server" CommandArgument="Prev" CommandName="Page" Enabled=" <%# ((GridView)Container.NamingContainer).PageIndex != 0 %>">上一页</asp:LinkButton>
<asp:LinkButton ID="LinkButtonNextPage" runat="server" CommandArgument="Next" CommandName="Page" Enabled=" <%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>">下一页</asp:LinkButton>
<asp:LinkButton ID="LinkButtonLastPage" runat="server" CommandArgument="Last" CommandName="Page" Enabled=" <%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>">尾页</asp:LinkButton>
(第 <asp:Label ID="LabelCurrentPage" runat="server" Text=" <%# ((GridView)Container.NamingContainer).PageIndex + 1 %>"> </asp:Label> 页,共 <asp:Label ID="LabelPageCount" runat="server" Text=" <%# ((GridView)Container.NamingContainer).PageCount %>"> </asp:Label> 页 <asp:Label ID="LabelTotalCount" runat="server" Text=' <%# (((GridView)Container.NamingContainer).DataSource is System.Collections.ICollection) ? string.Format(",{0} 条记录", ((System.Collections.ICollection)((GridView)Container.NamingContainer).DataSource).Count) : "" %>'> </asp:Label>)
</PagerTemplate>增加一个TextBox和一个Button,TextBox里面输入数字,然后点击Button,可以直接在上面的代加里加吗?应该怎么加?谢谢各位了
<asp:LinkButton ID="LinkButtonFirstPage" runat="server" CommandArgument="First" CommandName="Page" Enabled=" <%# ((GridView)Container.NamingContainer).PageIndex != 0 %>">首页</asp:LinkButton>
<asp:LinkButton ID="LinkButtonPreviousPage" runat="server" CommandArgument="Prev" CommandName="Page" Enabled=" <%# ((GridView)Container.NamingContainer).PageIndex != 0 %>">上一页</asp:LinkButton>
<asp:LinkButton ID="LinkButtonNextPage" runat="server" CommandArgument="Next" CommandName="Page" Enabled=" <%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>">下一页</asp:LinkButton>
<asp:LinkButton ID="LinkButtonLastPage" runat="server" CommandArgument="Last" CommandName="Page" Enabled=" <%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>">尾页</asp:LinkButton>
(第 <asp:Label ID="LabelCurrentPage" runat="server" Text=" <%# ((GridView)Container.NamingContainer).PageIndex + 1 %>"> </asp:Label> 页,共 <asp:Label ID="LabelPageCount" runat="server" Text=" <%# ((GridView)Container.NamingContainer).PageCount %>"> </asp:Label> 页 <asp:Label ID="LabelTotalCount" runat="server" Text=' <%# (((GridView)Container.NamingContainer).DataSource is System.Collections.ICollection) ? string.Format(",{0} 条记录", ((System.Collections.ICollection)((GridView)Container.NamingContainer).DataSource).Count) : "" %>'> </asp:Label>)
</PagerTemplate>增加一个TextBox和一个Button,TextBox里面输入数字,然后点击Button,可以直接在上面的代加里加吗?应该怎么加?谢谢各位了
/// <summary>
/// 根据输入的页数跳转到相应的页数
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void lbJump_Click(object sender, EventArgs e)
{
int page = 0;
try
{
page = Convert.ToInt32(this.txtPager.Text.Trim())-1;
PagedDataSource pdsProduct = new PagedDataSource();
pdsProduct.DataSource = ProductManager.GetAllProduct();
pdsProduct.AllowPaging = true;
pdsProduct.PageSize = 3;
if (page<0||page>pdsProduct.PageCount-1)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('您输入的数字不再范围内!');</script>");
}
else
{
Pager = page;
DataBinds();
} }
catch (Exception)
{
Page.ClientScript.RegisterStartupScript(this.GetType(),"","<script>alert('请输入数字!');</script>");
}
}
<asp:TextBox ID="txtGo" runat="server"></asp:TextBox>
<asp:Button ID="btnGo" runat="server" Text="GO" OnClick="btnGo_Click" /> </PagerTemplate>
//后台
protected void btnGO_Click(object sender, EventArgs e)
{
this.GridView1.CurrentPageIndex = txtGo.Text;
... 获取代码,绑定数据
}
ShowPageIndexBox="Always" FirstPageText='<font face="webdings">9</font>' LastPageText='<font face="webdings">:</font>'
NextPageText='<font face="webdings">4</font>' PrevPageText='<font face="webdings">3</font>'
ShowInputBox="Always" CustomInfoSectionWidth="80%" AlwaysShow="True" ShowCustomInfoSection="Left"
PageSize="10">
</webdiyer:AspNetPager>
if (e.NewPageIndwx < 0)
{
TextBox t = (TextBox)g.BottomPagerRow.FindControl("文本框ID");
int pa = int.Parse(t.Text);
if (pa <= 0)
{
g.PageIndex = 0;
}
else
{
g.PageIndex = pa - 1;
}
}
else
{
g.PageIndex = e.NewPageIndex;
}
/// 跳转
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnGo_Click(object sender, EventArgs e)
{
if (this.txtCurrentPage.Text != null && txtCurrentPage.Text != "")
{
if (Int32.TryParse(txtCurrentPage.Text, out _pageCurrent) && Int32.Parse(txtCurrentPage.Text) > 0)
{
this.Bind();
this.getLogDataSet(modlelog.SLTName); //绑定数据代码,就不贴上来了。
}
else
{
MessageBox.Show("Enter only integer greater than 0!");
}
}
} public void Bind()
{
this.btnGo.Enabled = true;
this.txtCurrentPage.Enabled = true;
if (this.PageCurrent > this.PageCount)
{
this.PageCurrent = this.PageCount;
}
if (this.PageCount == 1)
{
this.PageCurrent = 1;
}
tslblPageCout.Text = this.PageCount.ToString();
this.tslblMaxPage.Text = "RecordCounts: " + this.NMax.ToString();
this.txtCurrentPage.Text = this.PageCurrent.ToString(); if (this.PageCurrent == 1)
{
this.btnPrev.Enabled = false;
this.btnFirst.Enabled = false;
}
else
{
btnPrev.Enabled = true;
btnFirst.Enabled = true;
} if (this.PageCurrent == this.PageCount)
{
this.btnLast.Enabled = false;
this.btnNext.Enabled = false;
}
else
{
btnLast.Enabled = true;
btnNext.Enabled = true;
} if (this.NMax == 0)
{
btnNext.Enabled = false;
btnLast.Enabled = false;
btnFirst.Enabled = false;
btnPrev.Enabled = false;
}
}
AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="SqlDataSource1"
ondatabound="CustomersGridView_DataBound1" Width="800px">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="True"
SortExpression="ID" />
</Columns>
<PagerTemplate>
<div style="text-align: right;">
<asp:LinkButton ID="cmdFirstPage" runat="server" CommandName="Page" CommandArgument="First"
Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex!=0 %>">首页</asp:LinkButton>
<asp:LinkButton ID="cmdPreview" runat="server" CommandArgument="Prev" CommandName="Page"
Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex!=0 %>">前页</asp:LinkButton>
<asp:LinkButton ID="cmdNext" runat="server" CommandName="Page" CommandArgument="Next"
Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex!=((GridView)Container.Parent.Parent).PageCount-1 %>">后页</asp:LinkButton>
<asp:LinkButton ID="cmdLastPage" runat="server" CommandArgument="Last" CommandName="Page"
Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex!=((GridView)Container.Parent.Parent).PageCount-1 %>">尾页</asp:LinkButton>
<asp:label id="CurrentPageLabel"
forecolor="Blue"
runat="server"/>
跳转
<asp:dropdownlist id="PageDropDownList"
autopostback="true"
onselectedindexchanged="PageDropDownList_SelectedIndexChanged"
runat="server"/>
页 跳转第
<asp:TextBox ID="PageNum" runat="server" Height="16px" Width="34px"></asp:TextBox>
页
<asp:Button ID="Button1" runat="server" Text="提交" onclick="Button1_Click" ValidationGroup="page" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="PageNum" ErrorMessage="页码请输入" ValidationGroup="page"></asp:RequiredFieldValidator>
<asp:RangeValidator ID="RangeValidator1" runat="server"
ControlToValidate="PageNum" ErrorMessage="页面超出范围" MaximumValue='<%# ((GridView)Container.Parent.Parent).PageCount %>'
MinimumValue="1" Type="Integer" ValidationGroup="page"></asp:RangeValidator>
</div>
</PagerTemplate>
</asp:GridView> public void PageDropDownList_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow pagerRow = CustomersGridView.BottomPagerRow;
DropDownList pageList = (DropDownList)pagerRow.Cells[0].FindControl("PageDropDownList");
CustomersGridView.PageIndex = pageList.SelectedIndex; } protected void CustomersGridView_DataBound1(object sender, EventArgs e)
{
GridViewRow pagerRow = CustomersGridView.BottomPagerRow;
DropDownList pageList = (DropDownList)pagerRow.Cells[0].FindControl("PageDropDownList");
Label pageLabel = (Label)pagerRow.Cells[0].FindControl("CurrentPageLabel");
if(pageList != null)
{
for(int i=0; i<CustomersGridView.PageCount; i++)
{
int pageNumber = i + 1;
ListItem item = new ListItem(pageNumber.ToString());
if(i==CustomersGridView.PageIndex)
{
item.Selected = true;
}
pageList.Items.Add(item);
}
}
if(pageLabel != null)
{ int currentPage = CustomersGridView.PageIndex + 1;
pageLabel.Text = "Page " + currentPage.ToString() +" of " + CustomersGridView.PageCount.ToString();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
GridViewRow pagerRow = CustomersGridView.BottomPagerRow;
TextBox tb = (TextBox)pagerRow.Cells[0].FindControl("PageNum");
CustomersGridView.PageIndex =Convert.ToInt32(tb.Text.ToString())-1;
}
响应button事件,在后台写代码就可以了啊GridView1.PageIndex = Convert.toInt32(TextBox1.Text);
Bind();大致思路就是这样子的啊
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" Height="448px"
onpageindexchanging="GridView1_PageIndexChanging" Width="700px"
AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="序号">
<ItemTemplate>
<asp:Label ID="Label1" runat="server"
Text="<%# GridView1.PageIndex*GridView1.PageSize+GridView1.Rows.Count+1 %>"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="name" />
</Columns>
<PagerTemplate/>
</asp:GridView>
</div>
<div>
<asp:LinkButton ID="LinkButtonFirstPage" runat="server" CommandArgument="First"
CommandName="Page"
Enabled=" <%# ((GridView)Container.NamingContainer).PageIndex != 0 %>"
CausesValidation="False" onclick="LinkButtonFirstPage_Click">首页</asp:LinkButton>
<asp:LinkButton ID="LinkButtonPreviousPage" runat="server" CommandArgument="Prev"
CommandName="Page"
Enabled=" <%# ((GridView)Container.NamingContainer).PageIndex != 0 %>"
CausesValidation="False"
onclick="LinkButtonPreviousPage_Click">上一页</asp:LinkButton>
<asp:LinkButton ID="LinkButtonNextPage" runat="server" CommandArgument="Next"
CommandName="Page"
Enabled=" <%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>"
CausesValidation="False" onclick="LinkButtonNextPage_Click">下一页</asp:LinkButton>
<asp:LinkButton ID="LinkButtonLastPage" runat="server" CommandArgument="Last"
CommandName="Page"
Enabled=" <%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>"
CausesValidation="False" onclick="LinkButtonLastPage_Click">尾页</asp:LinkButton>
<asp:TextBox ID="txtPage" runat="server" Width="19px"
Text="<%# ((GridView)Container.Parent.Parent).PageIndex+1 %>"></asp:TextBox>
<asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click">GO</asp:LinkButton>
</div>
</form>
</body>
</html>
//分页方法
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
try
{
if (e.NewPageIndex < 0)
{
TextBox t = (TextBox)GridView1.BottomPagerRow.FindControl("txtPage");
int pa = int.Parse(t.Text);
if (pa <= 0)
{
GridView1.PageIndex = 0;
}
else
{
GridView1.PageIndex = pa - 1;
}
}
else
{
GridView1.PageIndex = e.NewPageIndex;
}
DataTable dt = (DataTable)ViewState["data"];
GridView1.DataSource = dt;
GridView1.DataBind();
}
catch{ }
}
//跳转
protected void LinkButton1_Click(object sender, EventArgs e)
{
try
{
int page = Convert.ToInt32(txtPage.Text);
//TextBox t = (TextBox)GridView1.BottomPagerRow.FindControl("TextBox1");
//int pa = int.Parse(t.Text);
GridView1_PageIndexChanging(GridView1, new GridViewPageEventArgs(page - 1));
}
catch{ }
} //首页
protected void LinkButtonFirstPage_Click(object sender, EventArgs e)
{
GridView1_PageIndexChanging(GridView1, new GridViewPageEventArgs(0));
}
//上一页
protected void LinkButtonPreviousPage_Click(object sender, EventArgs e)
{
GridView1_PageIndexChanging(GridView1, new GridViewPageEventArgs(GridView1.PageIndex-1));
}
//下一页
protected void LinkButtonNextPage_Click(object sender, EventArgs e)
{
GridView1_PageIndexChanging(GridView1, new GridViewPageEventArgs(GridView1.PageIndex+1));
}
//尾页
protected void LinkButtonLastPage_Click(object sender, EventArgs e)
{
GridView1_PageIndexChanging(GridView1, new GridViewPageEventArgs(GridView1.PageCount-1)); }
select top 5 * from users
where id not IN (select top (5*(5-1)) * from users)(大概意思在那,语句可能有错)就是查询5条数据,不在前20条的5条数据 5*(5-1);当文本框输入几的时候X-1的“X”传进去计算第几页的数字,查出结果 进行显示,不就OK?
protected void btnLoginPage_Click(object sender, EventArgs e)
{
if (txtPage.Text == "" || txtPage.Text == null)
{ }
else
{
int page = Convert.ToInt32(txtPage.Text.Trim());
if (page < 0 || page > gridView.PageCount)
{
//超出总页面
gridView.PageIndex = page;
}
else
{
gridView.PageIndex = page - 1;
bind();
}
}
}