GridView,Repeater分页控件:WebPager(开源)

一、特点:
可以用在母板、MS Ajax等控件嵌套的任何地方,
支持GridView,Repeater等数据控件的分页
二、属性:
1. PagerStyle: 设置分页样式(NextPrev,NumericPages)
2. ControlToPaginate: 指定要实现分页的控件ID(
数据控件本身不需要进行数据绑定了,只需对WebPager进行数据绑定就行了)
3. PageSize: 获取或设置要在单页上显示的项数
4. CurrentPageIndex: 获取或设置当前页的索引
三、事件:
1. OnPageIndexChanged: 执行分页时触发的分页事件

四、源码下载

五、示例: (Repeater用法于此类似)

< asp:GridView  ID ="GridView1"  runat ="server"  Width ="100%"  AutoGenerateColumns ="true"
    OnRowDataBound
="GridView1_RowDataBound"  AllowSorting ="True"  OnSorting ="GridView1_Sorting" >
    
< PagerSettings  Visible ="False"   />
</ asp:GridView >
< cc1:WebPager  ID ="WebPager1"  runat ="server"  PagerStyle ="NextPrev"  ControlToPaginate ="GridView1"
    PageSize
="5"  OnPageIndexChanged ="WebPager1_PageIndexChanged"   />

Page事件 #region Page事件
Workflow.BLL.Workflow myBiz 
= new Workflow.BLL.Workflow();
protected void Page_Load(object sender, EventArgs e)
{
    
if (!Page.IsPostBack)
    
{
        GetData();
//重新获取操作后的数据源
        BindGrid();//绑定GridView,为删除服务
    }

}

#endregion


Gridview ---------------------------------------------------------- #region Gridview ----------------------------------------------------------
数据绑定#region 数据绑定
/**//// <summary>
/// 获取数据源
/// </summary>

private void GetData()
{
    
this.DataSource = myBiz.GetFlowDoing(Framework.Globals.CurrentUser.UserID).Tables[0];
}

/**//// <summary>
/// 初始化绑定
/// </summary>

private void BindGrid()
{
    WebPager1.DataSource 
= this.DataSource;
    WebPager1.DataBind();
}

#endregion


排序#region 排序
/**//// <summary>
/// 排序
/// </summary>

protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
    
string sortDirection = "";
    
string sortExpression = e.SortExpression;
    
if (this.Sort_Direction == SortDirection.Ascending)
    
{
        
this.Sort_Direction = SortDirection.Descending;
        sortDirection 
= "DESC";
    }

    
else
    
{
        
this.Sort_Direction = SortDirection.Ascending;
        sortDirection 
= "ASC";
    }

    DataView Source 
= new DataView(this.DataSource);
    Source.Sort 
= e.SortExpression + " " + sortDirection;

    
//GridView1.DataSource = Source;//不能再用此绑定,否则影响排序后的分页。
    
//GridView1.DataBind();
    this.DataSource = Source.ToTable();//重新设置数据源,绑定
    BindGrid();
}


#endregion


分页#region 分页
protected void WebPager1_PageIndexChanged(object sender, wf.WebPager.PageChangedEventArgs e)
{
    WebPager1.CurrentPageIndex 
= e.NewPageIndex;
    WebPager1.DataSource 
= this.DataSource;
    WebPager1.DataBind();
}

#endregion


#endregion


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值