问题描述
我在的Page_Load
数据源绑定到一个转发
。
I have a datasource in Page_Load
binded to a repeater
.
我写结果到的ItemDataBound页但是当它是数据的最后一行我要求它做一些事情略有不同。
I am writing the results to the page in ItemDataBound but when it's the last row of data I require it to do something slightly different.
如何访问在Page_Load中的数据源的行数从内部的ItemDataBound中继的?
How do I access the row count of a data source in Page_Load from within ItemDataBound of the repeater?
我试过:
Dim iCount As Integer
iCount = (reWorkTags.Items.Count - 1)
If e.Item.ItemIndex = iCount Then
'do for the last row
Else
'do for all other rows
End If
但e.Item.ItemIndex和ICOUNT都等于相同的每一行。
But both e.Item.ItemIndex and iCount equal the same for every row.
感谢您的帮助。
学家
Thanks for any help.J.
推荐答案
当时特林避免使用会话,但得到它到底有一个工作。
Was tring to avoid using Sessions but got it working with one in the end.
我刚刚创建的行数的会议,并可以访问,从的ItemDataBound。
I just created a session of the row count and could access that from ItemDataBound.
Protected Sub reWorkTags_ItemDataBound(sender As Object, e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles reWorkTags.ItemDataBound
If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then
Dim rowView As System.Data.DataRowView
rowView = CType(e.Item.DataItem, System.Data.DataRowView)
Dim link As New HyperLink
link.Text = rowView("tag")
link.NavigateUrl = rowView("tagLink")
link.ToolTip = "View more " & rowView("tag") & " work samples"
Dim comma As New LiteralControl
comma.Text = ", "
Dim workTags1 As PlaceHolder = CType(e.Item.FindControl("Linkholder"), PlaceHolder)
If e.Item.ItemIndex = Session("iCount") Then
workTags1.Controls.Add(link)
Else
workTags1.Controls.Add(link)
workTags1.Controls.Add(comma)
End If
End If
End Sub
这篇关于得到的ItemDataBound行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!