下面是GirdView的代码,其中我使用了一个正常工作的PagerTemplate,除了属性PagerSettings-PageButtonCount =“3”。 我希望一次只显示三个页码,通常由PageButtonCount属性完成。
Asp.Net
<asp:GridView
id="grdMovies"
DataSourceID="srcMovies"
AllowPaging="true"
PageSize="3"
Runat="server"
PagerSettings-PageButtonCount="3"
OnDataBound="grdMovies_DataBound">
<PagerTemplate>
<table>
<tr>
<td>
<asp:LinkButton
id="lnkPrevious"
Text="< Prev"
CommandName="Page"
CommandArgument="Prev"
ToolTip="Previous Page"
Runat="server" />
</td>
<td>
<asp:Menu
id="menuPager"
Orientation="Horizontal"
OnMenuItemClick="menuPager_MenuItemClick"
CssClass="menu"
Runat="server" />
</td>
<td>
<asp:LinkButton
id="lnkNext"
Text="Next >"
CommandName="Page"
CommandArgument="Next"
ToolTip="Next Page"
Runat="server" />
</td>
</tr>
</table>
</PagerTemplate>
</asp:GridView>
C#代码
<script runat="server">
protected void grdMovies_DataBound(object sender, EventArgs e)
{
Menu menuPager = (Menu)grdMovies.BottomPagerRow.FindControl("menuPager");
for (int i = 0; i < grdMovies.PageCount; i++)
{
MenuItem item = new MenuItem();
item.Text = (i + 1).ToString();
item.Value = i.ToString();
if (grdMovies.PageIndex == i)
item.Selected = true;
menuPager.Items.Add(item);
}
}
protected void menuPager_MenuItemClick(object sender, MenuEventArgs e)
{
grdMovies.PageIndex = Int32.Parse(e.Item.Value);
}
</script>
我怎样才能做到这一点。 感谢..
答案 0 :(得分:0)
我猜您需要在gridview中添加此属性
PagerSettings-Mode="NumericFirstLast"