我有一个转发器:
<asp:Repeater ID="rptSessions" runat="server">
在这里我有另一个转发器:
<asp:Repeater ID="rptPeople" runat="server" OnItemDataBound="rptPeople_ItemDataBound">
在我的父转发器上的ItemDataBound上,我正在设置子转发器的数据源。
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
<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,具体取决于列Dietary
是否存在于其数据源中。我尝试了以下方法:
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似乎是Nothing
答案 0 :(得分:0)
最后我这样做了:
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