国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

asp.net中讓Repeater和GridView支持DataPager分頁

2024-07-10 12:41:29
字體:
供稿:網(wǎng)友
改造辦法是自己寫一個控件,讓它繼承GridView或Repeater,并實(shí)現(xiàn)IPageableItemContainer 接口。下面要發(fā)的是國外某高手寫的代碼,測試有效。具體使用的時候,要建一個類庫項(xiàng)目,把代碼編譯成dll后,就可以添加到VS的工具箱里了!
一、自定義Repeater
代碼如下:
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WYJ.Web.Controls
{
/// <summary>
/// Repeater with support for DataPager
/// </summary>
[ToolboxData("<{0}:DataPagerRepeater runat=server PersistentDataSource=true></{0}:DataPagerRepeater>")]
public class DataPagerRepeater : Repeater, System.Web.UI.WebControls.IPageableItemContainer, INamingContainer
{
/// <summary>
/// Number of rows to show
/// </summary>
public int MaximumRows { get { return ViewState["MaximumRows"] != null ? (int)ViewState["MaximumRows"] : -1; } }
/// <summary>
/// First row to show
/// </summary>
public int StartRowIndex { get { return ViewState["StartRowIndex"] != null ? (int)ViewState["StartRowIndex"] : -1; } }
/// <summary>
/// Total rows. When PagingInDataSource is set to true you must get the total records from the datasource (without paging) at the FetchingData event
/// When PagingInDataSource is set to true you also need to set this when you load the data the first time.
/// </summary>
public int TotalRows { get { return ViewState["TotalRows"] != null ? (int)ViewState["TotalRows"] : -1; } set { ViewState["TotalRows"] = value; } }
/// <summary>
/// If repeater should store data source in view state. If false you need to get and bind data at post back. When using a connected data source this is 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 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 get and rebind data at the FetchingData event.
/// If this is true 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 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)
發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 鸡东县| 福贡县| 岚皋县| 渭南市| 饶阳县| 富蕴县| 南川市| 屏东市| 霞浦县| 宁蒗| 伊春市| 招远市| 玉溪市| 尖扎县| 涞源县| 盖州市| 湟源县| 雅江县| 邓州市| 襄樊市| 临漳县| 天长市| 西城区| 石首市| 蓝田县| 明水县| 南部县| 邮箱| 阿图什市| 铅山县| 友谊县| 黑河市| 霸州市| 晋江市| 汶上县| 西乌珠穆沁旗| 莱州市| 巍山| 木兰县| 汤阴县| 稷山县|