2012-06-19 35 views
0

使用Telerik RadGrid我绑定了一个数据源并将方法附加到OnItemDataBound事件中。检查项目是否是OnItemDataBind中的最后一个

<telerik:RadGrid ID="myGrid" runat="server" 
    DataSourceID="myDataSource" 
    OnItemDataBound="myMethod" 
    > 

我一直在努力寻找解决方案一段时间没有运气。我如何检查被绑定的物品是最后绑定的物品。例如,下面的方法将被称为每个记录

protected void myMethod(object sender, GridItemEventArgs e) 
{ 
    //some condition to check whether the current item is the last 
} 

我希望如果解释清楚我的问题。先谢谢你。

+0

我有完全相同的问题,环顾四周,但coudnt发现做任何清洁方式,所以不得不重新思考方法并采用另一种方法。如果你说出为什么你想要我们可以拿出差异的方法 –

+0

目前只是为了缩小外观和感觉。我知道这可以用JavaScript来完成,但我想保留在服务器上,因为表中的其他行已经有一些类似的代码。 –

回答

3
if (e.Item.ItemType == GridItemType.Item || e.Item.ItemType == GridItemType.AlternatingItem) 
{ 
    if (e.Item.DataSetIndex == e.Item.OwnerTableView.DataSourceCount - 1) 
    { 
     //Last Grid Item 
    } 
} 

如果寻呼,查询页面上的最后一个项目:

(e.Item.ItemIndex == e.Item.OwnerTableView.PageSize - 1) 
相关问题