<asp:ListView ID="ListView1" runat="server" GroupItemCount="5">
<LayoutTemplate>
<table runat="server" id="table1">
<tr runat="server" id="groupPlaceholder">
</tr>
</table>
</LayoutTemplate>
<GroupTemplate>
<tr runat="server" id="tableRow">
<td runat="server" id="itemPlaceholder" />
</tr>
</GroupTemplate>
<ItemTemplate>
<td id="Td1" runat="server">
<%-- Data-bound content. --%>
<asp:Label ID="NameLabel" runat="server" Text='<%#Eval("yyyy") %>' />
</td>
<td id="Td2" runat="server">
<%-- Data-bound content. --%>
<asp:Label ID="NameLabel" runat="server" Text='<%#Eval("nnnn") %>' />
</td>
</ItemTemplate>
</asp:ListView>
var by1 = from x in model.x
xxxx
select new
{
x.yyyy
};
ListView1.DataSource = by1;
ListView1.DataBind();
var by2 = from z in model.z
zzzz
select new
{
z.nnnn
};
ListView1.DataSource = by2;
ListView1.DataBind();
这是一个示例(不需要像这样写作) 我不知道如何从2个不同的查询中获取一个列表不同的属性。 像:
zzzzz:1111
zzzzz:2222
nnnn:ffff
nnnn:gggg
zzzz:3333
感谢。
答案 0 :(得分:0)
看一下这个例子我向你展示了Linq Union方法。这仅适用于Lists / IEnum的类型相同(在我们的例子中为Model
)。
void Main()
{
List<Model> by1 = new List<Model>();
by1.Add(new Model {Name = "zzzz",Value = "1111" });
by1.Add(new Model {Name = "fdgdfg",Value = "1234"});
by1.Add(new Model {Name = "zzzz",Value = "2222"});
List<Model> by2 = new List<Model>();
by1.Add(new Model {Name = "nnnn",Value = "ffff"});
by1.Add(new Model {Name = "nnnn",Value = "gggg"});
by1.Add(new Model {Name = "zzzz",Value = "3333"});
// Join the results of by1 and by2 as both are List<Model>
object dataSource = by1.Union(by2); // Results in a IEnumerable<Model>
// Bind the dataSource to the ListView
ListView1.DataSource = dataSource;
ListView1.DataBind();
}
和模型
public class Model {
public string Name { get;set;}
public string Value { get;set;}
}
修改强>
你可能'喜欢',甚至选择联盟成为匿名类型。例如:
object dataSource = by1.Union(by2).Select(item=>new
{
yyyy = item.Name,
nnnn = item.Value
});
这将为您提供具有yyyy和nnnn属性的IEnumerable。