Using System.Web.UI; Using System.Web.UI.WebControls; Namespace WYJ. Web.Controls { ///<summary> ///Repeater with support for Datapa GER ///</summary> [ToolBoxData ("<{0}:D atapagerrepeater runat =server persistentdatasource=true></{0}:D atapagerrepeater> ")] public class Datapagerrepeater:repeater, System.Web.UI.WebControls.IPageableItemContainer, INamingContainer { ///<summary> ///number of rows to show ///</summary> & nbsp; public int Maximumrows {get {return viewstate[' maximumrows ']!= null? (int) viewstate["Maximumrows"]:-1; } } ///<summary> / The A-row to show ///</summary> & nbsp; public int startRowIndex {get {return viewstate[' startrowindex ']!= null? (int) viewstate["startRowIndex"]:-1; } } <summary> Total rows. When Pagingindatasource are set to true you must get the total records from the DataSource (without paging) at the fetching Data Event When Pagingindatasource are set to true and you also need to set this then you load the data the </summary> public int Totalrows {get {viewstate["totalrows"]!= null? (int) viewstate["Totalrows"]:-1; set {viewstate["totalrows"] = value;}} <summary>
If repeater should store data source in view state. If false you are need to get and bind data at post. When using a connected the data source of the. Handled by the data source.
</summary>
public bool Persistentdatasource
{
get {return viewstate["Persistentdatasource"]!= null? (BOOL) viewstate["Persistentdatasource"]: true; }
set {viewstate["persistentdatasource"] = value;}
}
<summary>
Set to True if you are want to handle paging in the data source.
Ex If you are selecting data from the database and only select the current rows
You must set this property to True and rebind the Fetchingdata event.
The If is true to you must also set the Totalrecords property at the Fetchingdata event.
</summary>
<seealso cref= "Fetchingdata"/>
<seealso cref= "Totalrows"/>
public bool Pagingindatasource
{
get {return viewstate["Pageingindatasource"]!= null? (BOOL) viewstate["Pageingindatasource"]: false; }
set {viewstate["pageingindatasource"] = value;}
}
<summary>
Checks If you are need to rebind data source at postback
</summary>
public bool Needsdatasource
{
Get
{
if (Pagingindatasource)
return true;
if (Isboundusingdatasourceid = = False &&!) Page.IsPostBack)
return true;
if (Isboundusingdatasourceid = = False && Persistentdatasource = = False && Page.IsPostBack)
return true;
Else
return false;
}
} <summary> Loading ViewState </summary> <param name= "savedstate" ></param> protected override void LoadViewState (object savedstate) { Base. LoadViewState (savedstate); if (Page.IsPostBack) //{ if (! Isboundusingdatasourceid && persistentdatasource && viewstate["DataSource"]!= null)
// {
This. DataSource = viewstate["DataSource"];
This. DataBind (TRUE);
// }
if (Isboundusingdatasourceid)
// {
This. DataBind ();
// }
//}
} protected override void OnLoad (System.EventArgs e)
{
if (Page.IsPostBack)
{
if (needsdatasource && fetchingdata!= null)
{
if (Pagingindatasource)
{
Setpageproperties (startRowIndex, maximumrows, true);
}
Fetchingdata (this, null);
} if (! Isboundusingdatasourceid && persistentdatasource && viewstate["DataSource"]!= null)
{
This. DataSource = viewstate["DataSource"];
This. DataBind ();
}
if (Isboundusingdatasourceid)
{
This. DataBind ();
} } Base. OnLoad (e); } ///<summary> ///method used by pager to set totalrecords ///</summary> ///<param name= "startRowIndex" >startRowIndex</param> ///<param name= "Maximumrows" >MAXIMUMROWS</PARAM> ///<param name= "DataBind" >DATABIND</PARAM> public void setpageproperties (int startrowindex, int maximumrows, BOOL databind) { viewstate["startRowIndex"] = startRowIndex; viewstate["maximumrows"] = maximumrows; if (Totalrows >-1)
{
if (totalrowcountavailable!= null)
{
Totalrowcountavailable (This, new PageEventArgs (int) viewstate["startRowIndex"], (int) viewstate["Maximumrows"], Totalrows));
}
}
}
<summary>
Ondatapropertychanged
</summary>
protected override void Ondatapropertychanged ()
{
if (maximumrows!=-1 | | Isboundusingdatasourceid)
{
This. Requiresdatabinding = true;
}
Base. Ondatapropertychanged ();
} <summary>
Renders only current items selected by pager
</summary>
<param name= "Writer" ></param>
protected override void RenderChildren (HtmlTextWriter writer)
{
if (! Pagingindatasource && maximumrows!=-1)
{
foreach (RepeaterItem item in this. Items)
{
if (item. ItemType = = ListItemType.Item | | Item. ItemType = = ListItemType.AlternatingItem)
{
Item. Visible = false;
if (item. ItemIndex >= (int) viewstate["startRowIndex"] && item. ItemIndex < ((int) viewstate["startRowIndex"] + (int) viewstate["maximumrows"))
{
Item. Visible = true;
}
}
Else
{
Item. Visible = true;
}
}
}
Base. RenderChildren (writer);
} ///<summary> / Get Data ///</summary> ///<returns></returns> protected override System.Collections.IEnumerable GetData () { System.Collections.IEnumerable dataobjects = base. GetData (); if (dataobjects = null && this. DataSource!= null) { if (this. DataSource is System.Collections.IEnumerable) dataobjects = (System.Collections.IEnumerable) this. DataSource; Else DataObjects = ((System.ComponentModel.IListSource) this. DataSource). GetList (); } if (! Pagingindatasource && maximumrows!=-1 && dataobjects!= null) { int i =-1; if (dataobjects!= NULL) { i = 0; foreach (Object o in dataobjects) { i++; } } viewstate["totalrows"] = i; if (! Isboundusingdatasourceid && Persistentdatasource) viewstate["DataSource"] = this. DataSource; Setpageproperties (startRowIndex, maximumrows, true);
} if (Pagingindatasource &&! Page.IsPostBack) { Setpageproperties (startRowIndex, maximumrows, true); } return dataobjects; } <summary> Event when pager/repeater have counted total rows </summary> public event system.eventhandler<pageeventargs> Totalrowcountavailable; <summary> Event when Repeater gets the ' data on postback </summary> public event system.eventhandler<pageeventargs> Fetchingdata; } } |