嗨我必須在中繼器中顯示分層信息(它有四個級別)。爲此我決定使用嵌套中繼器控制。 我在MSDN上找到了這篇文章,http://support.microsoft.com/kb/306154,它顯示瞭如何使用嵌套中繼器獲得兩個級別的信息。 有人可以幫我把這個延伸到四個級別嗎? 一個示例代碼將非常appriciated。謝謝。C中的嵌套中繼器#
4
A
回答
15
HTML代碼:
<asp:Repeater ID="Repeater1" runat="server"
onitemdatabound="Repeater1_ItemDataBound">
<ItemTemplate>
<h1>
Repeater 1</h1>
<asp:Repeater ID="Repeater2" runat="server" onitemdatabound="Repeater2_ItemDataBound">
<ItemTemplate>
<h1>
Repeater 2
</h1>
<asp:Repeater ID="Repeater3" runat="server" onitemdatabound="Repeater3_ItemDataBound">
<ItemTemplate>
<h1>
Repeater 3
</h1>
<asp:Repeater ID="Repeater4" runat="server" onitemdatabound="Repeater4_ItemDataBound">
<ItemTemplate>
<h1>
Repeater 4
</h1>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
C#代碼:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt1 = new DataTable();
//Need to assign the Data in datatable
Repeater1.DataSource = dt1;
Repeater1.DataBind();
}
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater Repeater2 = (Repeater)(e.Item.FindControl("Repeater2"));
DataTable dt2 = new DataTable();
//Need to assign the Data in datatable
Repeater2.DataSource = dt2;
Repeater2.DataBind();
}
}
protected void Repeater2_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater Repeater3 = (Repeater)(e.Item.FindControl("Repeater3"));
DataTable dt3 = new DataTable();
//Need to assign the Data in datatable
Repeater3.DataSource = dt3;
Repeater3.DataBind();
}
}
protected void Repeater3_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater Repeater4 = (Repeater)(e.Item.FindControl("Repeater4"));
DataTable dt4 = new DataTable();
//Need to assign the Data in datatable
Repeater4.DataSource = dt4;
Repeater4.DataBind();
}
}
}
0
0
大廈,而不是建立你的表中的ItemDataBound功能上的第一個答案,你可以通過在您的表格數據Page_Load
,將其設置爲ViewState變量,然後在綁定時檢索它:
private DataTable GetCachedDataTable(string strTable)
{
DataTable dtableCached = (DataTable)this.ViewState[strTableCache];
return dtableCached;
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
this.ViewState["TblTwo_Cache"] = null;
DataTable tblOne = new DataTable();
DataTable tblTwo = new DataTable();
myFunctionReturningTwoTables(ref tblOne, ref tblTwo);
// Bind the first one
if (tblOne != null)
{
// This first line assumes an <asp:Panel ID=pnlMain runat=server>
// tag is added in front of the Repeater1 tag in the ASPX markup, above,
// and an </asp:Panel> tag is after the last </asp:Repeater> tag
Repeater rptr = pnlMain.FindControl("Repeater1") as Repeater;
rptr.ItemDataBound += new RepeaterItemEventHandler(rptrItemDataBound);
rptr.DataSource = tblOne;
rptr.DataBind();
}
// Cache the 2nd (and others...) like this
if (tblTwo != null)
{
this.ViewState["TblTwo_Cache"] = tblTwo;
}
}
}
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater rptr2 = e.Item.FindControl("Repeater2") as Repeater;
if (rptr2 != null)
{
DataTable dt = new DataTable();
// Now, pull it out of cache
dt = GetCachedDataTable("TblTwo_Cache");
if (dt != null)
{
rptr2.DataSource = dt;
rptr2.DataBind();
}
}
}
}
0
如果您應該使用強類型數據類型,最好使用ItemType
財產中<asp:Repeater>
控制可用,以便您可以嵌套<asp:Repeater>
控制的DataSource
屬性容易地設定爲<%#Container.DataItem %>
爲遵循每個嵌套中繼器相同的步驟。
代碼示例:
<asp:Repeater ID="associatedDataRepeater" runat="server">
<ItemTemplate>
<asp:Repeater runat="server" DataSource='<%#Container.DataItem %>'>
<ItemTemplate>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
相關問題
- 1. 嵌套中繼器
- 2. 嵌套中繼器
- 3. C++中的嵌套繼承
- 4. ItemDataBound嵌套中繼器
- 5. ASP嵌套中繼器ID
- 6. asp.net嵌套中繼器
- 7. 嵌套中繼
- 8. 使用asp.net中的嵌套中繼器
- 9. 嵌套中繼器顯示匹配父中繼器的數據
- 10. 如何在asp.net中嵌套中繼器
- 11. 在asp.net中嵌套中繼器
- 12. 與linq在中繼器嵌套的XML
- 13. 嵌套中繼器內的按鈕
- 14. 使用XMLNodeList的嵌套中繼器
- 15. ASP.NET中繼器控制與嵌套中繼器
- 16. 嵌套中繼器 - 分組數據
- 17. ASP.NET嵌套中繼器訪問元素
- 18. 數據嵌套angularjs結合中繼器
- 19. 動態嵌套中繼器ASP.net
- 20. 如何綁定嵌套中繼器?
- 21. XML到嵌套中繼器控制ASP.net
- 22. ASP.Net嵌套中繼器邏輯地獄
- 23. 嵌套中繼器 - 如何排序
- 24. 訪問控制:嵌套中繼器
- 25. 嵌套中繼器Asp.net ItemDataBound不叫?
- 26. 3嵌套中繼器與Sql表
- 27. 嵌套中繼器使用表標籤
- 28. asp.net複選框和嵌套中繼器
- 29. ASP.net:超過2個嵌套中繼器
- 30. 嵌套中繼器 - 從子中繼器訪問父節點中的控制器
我有必須使用中繼器來填充所需的數據的四個表。 (R1-T1,R2-T2,R3-T3,R4-T4)。 T1,T2,T3,T4全部使用具有1:M關係的外鍵連接。因此,一旦父母中繼器被填充,我如何提取該特定父母的詳細信息給子代中繼器。請幫忙。謝謝:) @ Deepak.Aggrawal –
您可以通過DataBinder.Eval(e.Item.DataItem,「T1」)獲取DataBound中的Id並根據您的父ID過濾您的結果。 –
嵌套中繼器(子中繼器)應只顯示與其父中繼器相關的詳細信息。我怎麼能做到這一點?你能否詳細說說你多說了些什麼?謝謝。 @ Deepak.Aggrawal –