How to Implement Using Paging in Aspx.net with C#
Is your email address OK? You are signed up for our newsletters but your email address is either unconfirmed, or has not been reconfirmed in a long time. Please click here to have a confirmation email sent so we can confirm your email address and start sending you newsletters again. Alternatively, you can update your subscriptions.
This is a preview of your article
Introduction
How to Implement the code using Paging and Repeater Control in Asp.net with C# .
.aspx Design Page:
To write the Code in Default.aspx page.
Here Used the Repeater Control and LinkButtons.
Page:
Font-Bold="true" runat="server"><%# Container.DataItem %>
.aspx.cs Page:
Then write the code to aspx.cs Page:
First we add the Library Files..
using System.Collections;
using System.Web.UI.HtmlControls;
Then write the Property to Class.. Property Names are FirstIndex,LastIndex,PageNumber. Get and set the values.
public int FirstIndex
{
get
{
if (ViewState["FirstIndex"] != null)
return Convert.ToInt32(ViewState["FirstIndex"]);
else
return 0;
}
set { ViewState["FirstIndex"] = value; }
}
public int LastIndex
{
get
{
if (ViewState["LastIndex"] != null)
return Convert.ToInt32(ViewState["LastIndex"]);
else
return 0;
}
set { ViewState["LastIndex"] = value; }
}
public int PageNumber
{
get
{
if (ViewState["PageNumber"] != null)
return Convert.ToInt32(ViewState["PageNumber"]);
else
return 0;
}
set { ViewState["PageNumber"] = value; }
}
Page Load()
Call the function LoadData() to PageLoad().
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
LoadData();
}
}
LoadData()
Then write the code function name of LoadData()
string keyword = Collections.MySession.keyword;
if (PatApptBiz.SelectModalityName(keyword).Count != 0)
{
List
PatAppt = PatApptBiz.SelectModalityName(keyword);
PagedDataSource pgitems = new PagedDataSource();
pgitems.DataSource = PatAppt;
pgitems.AllowPaging = true;
pgitems.PageSize = 10;
pgitems.CurrentPageIndex = PageNumber;
if (pgitems.PageCount > 0)
{
rptPages.Visible = true;
rptrpopupModalityRoom.Visible = true;
ArrayList pages = new ArrayList();
for (int i = 0; i < pgitems.PageCount; i++)
pages.Add((i + 1).ToString());
ViewState["TotalPages"] = pgitems.PageCount;
this.lblPageTotalInfo.Text = "Page" + (PageNumber + 1) + "of" + pgitems.PageCount;
this.lblPrevPage.Enabled = !pgitems.IsFirstPage;
this.lblNextPage.Enabled = !pgitems.IsLastPage;
this.lblFirstPage.Enabled = !pgitems.IsFirstPage;
this.lblLastPage.Enabled = !pgitems.IsLastPage;
rptPages.DataSource = pages;
rptPages.DataBind();
}
else
rptPages.Visible = false;
// rptrpopupIns.DataSource = refphysicians;
rptrpopupModalityRoom.DataSource = pgitems;
rptrpopupModalityRoom.DataBind();
// Collections.MySession.keyword = null;
}
else
{
lblMsg.Text = "No Records Found..";
this.lblPageTotalInfo.Text = "Page" + (PageNumber + 1) + "of" + (PageNumber + 1);
this.lblPrevPage.Enabled = false;
this.lblNextPage.Enabled = false;
this.lblFirstPage.Enabled = false;
this.lblLastPage.Enabled = false;
rptrpopupModalityRoom.Visible = false;
rptPages.Visible = false;
}
The Events of First, Prev, Next, Last Below:
protected void lblFirstPage_Click(object sender, EventArgs e)
{
PageNumber = 0;
this.LoadData();
}
protected void lblPrevPage_Click(object sender, EventArgs e)
{
PageNumber -= 1;
this.LoadData();
}
protected void lblNextPage_Click(object sender, EventArgs e)
{
PageNumber += 1;
this.LoadData();
}
protected void lblLastPage_Click(object sender, EventArgs e)
{
PageNumber = (Convert.ToInt32(ViewState["TotalPages"]) - 1);
this.LoadData();
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
rptPages.ItemCommand += new RepeaterCommandEventHandler(rptrpopupIns_OnItemCommand);
}
Repeater Control with OnItemCommand()
whenever execute OnItemCommand then below function will execute the code.
void rptrpopupIns_OnItemCommand(object source, RepeaterCommandEventArgs e)
{
PageNumber = Convert.ToInt32(e.CommandArgument) - 1;
LoadData();
}
Search button with Text Control
we want the search the items also binding the data to repeater control. so, use the below method..
protected void btnModalitySearch_Click(object sender, EventArgs e)
{
string keyword;
PageNumber = 0;
lblMsg.Text = "";
keyword = txtModalitySearchItem.Text;
Collections.MySession.keyword = keyword;
LoadData()
}
No comments:
Post a Comment