1
我有一箇中繼器:訪問嵌套轉發的數據源
<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爲我的孩子我直放站想隱藏取決於列Dietary
是否存在於它的數據源litDietaryRequirements。我試過如下:
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強制轉換似乎沒有什麼
DataItem的始終是'ListItemType.Header'沒有。也許這有助於:http://stackoverflow.com/questions/1411336/accessing-parent-data-in-nested-repeater-in-the-headertemplate – 2013-02-28 13:46:09
謝謝蒂姆,最後我使用父數據源的值來隱藏文字。 'DirectCast(DirectCast(e.Item.NamingContainer.NamingContainer,RepeaterItem).DataItem,DataRowView).Row.Item(「Lunch」)' – 2013-02-28 14:24:15
@JackPettinger:這個答案是否解決?如果是這樣,恕我直言,最好的辦法是發佈您的解決方案作爲答案。這樣,任何有類似問題的人都可以從你的答案中受益。 – 2013-02-28 15:04:31