ASP.NET: Can anyone provide some C # swap codes in Repeater or ListView elements so I can find out
1 answer
Here is the pager control I created to go to the PagerTemplate of the GridView. This is not the hardest piece, but it does show how the pager control can "see" the grid it belongs to and display a dropdown menu to navigate to a specific page.
DataPager.ascx
<%@ Control Language="C#" AutoEventWireup="true" EnableViewState="true" CodeFile="DataPager.ascx.cs" Inherits="Resources_Controls_DataPager" %>
<div>
<div style="float:right;">
<asp:ImageButton id="PageFirst"
CommandName="Page"
CommandArgument="First"
runat="server" />
<asp:ImageButton id="PagePrev"
CommandName="Page"
CommandArgument="Prev"
runat="server" />
Page
<asp:DropDownList id="pagesDropDown"
autopostback="true"
OnSelectedIndexChanged="pagesDropDown_SelectedIndexChanged"
runat="server" />
<asp:Label id="pageTotalPages" runat="server" />
<asp:ImageButton ID="PageNext"
CommandName="Page"
CommandArgument="Next"
runat="server" />
<asp:ImageButton ID="PageLast"
CommandName="Page"
CommandArgument="Last"
runat="server" />
</div>
<div style="clear:both;"></div>
</div>
DataPager.ascx.cs
public partial class Resources_Controls_DataPager : System.Web.UI.UserControl
{
#region Property: ParentGrid
public GridView ParentGrid
{
get { return (GridView)Parent.Parent.Parent.Parent; }
}
#endregion
protected void Page_Load(object sender, EventArgs e)
{
FillPage();
}
public void FillPage()
{
if (ParentGrid != null && pagesDropDown.Items.Count == 0)
{
pagesDropDown.Items.Clear();
for (int ix = 0; ix < ParentGrid.PageCount; ix++)
{
ListItem item = new ListItem((ix + 1).ToString());
item.Selected = (ix == ParentGrid.PageIndex);
pagesDropDown.Items.Add(item);
}
if (pagesDropDown.Items.Count == 0)
pagesDropDown.Items.Add(new ListItem("0"));
pageTotalPages.Text = String.Format("of {0}", ParentGrid.PageCount);
}
}
protected void pagesDropDown_SelectedIndexChanged(object sender, EventArgs e)
{
ParentGrid.PageIndex = pagesDropDown.SelectedIndex;
}
}
+1
source to share