![](/img/trans.png)
[英]How can I use a List<> Collection as a Repeater Datasource in ASP.NET with C#
[英]Print property name when using a List<List<>> Collection as a Repeater Datasource in ASP.NET with C#
對於某些原材料(例如銅,鋁,油,碳等),我將它們分為類型(金屬,油)。
var metals = new List<RawMaterial> { rMat, rMat2 };
var oil = new List<RawMaterial> {rMat3, rMat4};
var allMetals = new List<List<RawMaterial>> {metals, oil};
repOuterMetalGroup.DataSource = allMetals;
repOuterMetalGroup.DataBind();
<asp:Repeater runat="server" ID="repOuterMetalGroup" OnItemDataBound="repOuterMetalGroup_OnItemDataBound">
<ItemTemplate>
<asp:Label runat="server" ID="lblMetalName"></asp:Label>
</ItemTemplate>
</asp:Repeater>
protected void repOuterMetalGroup_OnItemDataBound(object sender, RepeaterItemEventArgs e)
{
var lblMetalName = (Label)e.Item.FindControl("lblMetalName");
lblMetalName.Text = e.Item.DataItem.ToString();
}
對於標簽lblMetalName
我想顯示metails
oil
和oil
但是我兩次跟隨行兩次System.Collections.Generic.List
1`
我認為首先打印groupName即(金屬,油),然后在中繼器內部使用另一個中繼器顯示有關材料的詳細信息。 但是我停留在第一點。 請建議! 這是RawMaterial
類的代碼:
public class RawMaterial
{
public string Name;
public string Source;
public string Unit;
public DateTime Date;
public decimal Value;
}
您可能應該改用字典:
var allMetals = new Dictionary<<string>, List<RawMaterial>> {
{"Metals", metals}
{"Oil", oil}
};
現在您可以獲得名稱。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.