[英]Print property name when using a List<List<>> Collection as a Repeater Datasource in ASP.NET with C#
For some raw materials(eg coper, aluminium, oil, carbon etc.) I have grouped them into types(Metal , Oil). 对于某些原材料(例如铜,铝,油,碳等),我将它们分为类型(金属,油)。
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();
}
For the label lblMetalName
I want to show metails
and oil
But I am getting following line two times System.Collections.Generic.List
1` 对于标签
lblMetalName
我想显示metails
oil
和oil
但是我两次跟随行两次System.Collections.Generic.List
1`
I thought that first print the groupName ie (metal,oil) then inside the repeater use another repeater to show the details about the material. 我认为首先打印groupName即(金属,油),然后在中继器内部使用另一个中继器显示有关材料的详细信息。 But I am stuck at the first point.
但是我停留在第一点。 Please suggest !!
请建议! Here is the code for the class
RawMaterial
: 这是
RawMaterial
类的代码:
public class RawMaterial
{
public string Name;
public string Source;
public string Unit;
public DateTime Date;
public decimal Value;
}
You should probably use a dictionary instead: 您可能应该改用字典:
var allMetals = new Dictionary<<string>, List<RawMaterial>> {
{"Metals", metals}
{"Oil", oil}
};
Now you can get the names. 现在您可以获得名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.