访问嵌套中继器的数据源 [英] Accessing a nested repeater's datasource
本文介绍了访问嵌套中继器的数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个中继器:
< ASP:直放站ID =rptSessions=服务器>
这里面我有另一个中继器:
Inside this I have another repeater:
<asp:Repeater ID="rptPeople" runat="server" OnItemDataBound="rptPeople_ItemDataBound">
在我的父母直放站的ItemDataBound,我设置数据源为孩子中继器。
On the ItemDataBound on my parent repeater, I am setting the datasource for the child repeater.
Dim dtPeople As New DataTable
dtPeople.Columns.Add("FirstName")
dtPeople.Columns.Add("LastName")
dtPeople.Columns.Add("Company")
If e.Item.DataItem("Lunch") = True Then dtPeople.Columns.Add("Dietary") <-- ***
rptPeople.DataSource = dtPeople
rptPeople.DataBind()
现在考虑的HTML我的孩子转发
Now consider the html for my child repeater
<asp:Repeater ID="rptPeople" runat="server" OnItemDataBound="rptPeople_ItemDataBound">
<HeaderTemplate>
<table>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Company</th>
<asp:Literal ID="litDietaryRequirements" runat="server"><th>Dietary Requirements</th></asp:Literal>
</tr>
</HeaderTemplate>
.....
在的ItemDataBound我的孩子我直放站想隐藏取决于列饮食
无论是在它的数据源存在litDietaryRequirements。我试过如下:
On the ItemDataBound for my child repeater I would like to hide litDietaryRequirements depending on whether the column Dietary
exists in it's datasource. I tried the following:
If e.Item.ItemType = ListItemType.Header Then
DirectCast(e.Item.FindControl("litDietaryRequirements"), Literal).Visible = DirectCast(e.Item.DataItem, DataRowView).Row.Table.Columns.Contains("Lunch")
End If
e.Item.DataItem似乎没有什么
e.Item.DataItem seems to be Nothing
推荐答案
在最后,我这样做:
If e.Item.ItemType = ListItemType.Header Then
Dim LunchRequired As Boolean = DirectCast(DirectCast(e.Item.NamingContainer.NamingContainer, RepeaterItem).DataItem, DataRowView).Row.Item("Lunch")
DirectCast(e.Item.FindControl("litDietaryRequirements"), Literal).Visible = LunchRequired
End If
这篇关于访问嵌套中继器的数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文