如何绑定两个不同的列表一个gridview? [英] How to bind a gridview with two different lists?

查看:146
本文介绍了如何绑定两个不同的列表一个gridview?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个不同类型的列表

I have two lists of different types

List<Report>
List<Newsletter>

有没有绑定两个列表的GridView的方法吗?这两个类不是从一个共同的接口实现的。

Is there a way to bind a gridview with both lists? Both classes are not implemented from a common interface.

我只需要对象属性中显示的名称状态。我的意思是,我要绑定的属性类型是常见的两种列表。

I just need to display the name and status within the object properties. I mean, the type of the properties i want to bind is common to both list.

推荐答案

也许是这样的:

ASPX

<asp:GridView ID="gv" runat="server">
    <Columns>
        <asp:BoundField DataField="name" HeaderText="Name" />
        <asp:BoundField DataField="status" HeaderText="Status" />
    </Columns>
</asp:GridView>

CS

gv.DataSource=reportList
              .Select(x =>  new {x.Status,Name= x.text })
              .Concat(
              newsList
              .Select(x =>  new {Status=x.Status.ToString(),Name= x.text }) );
gv.DataBind();

这篇关于如何绑定两个不同的列表一个gridview?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆