GridView的绑定到IList<&BusinessObject的GT;包含一个IList<&BusinessObject的GT; [英] Binding Gridview to IList<BusinessObject> that contains an IList<BusinessObject>

查看:143
本文介绍了GridView的绑定到IList<&BusinessObject的GT;包含一个IList<&BusinessObject的GT;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在遇到麻烦找出如何自定义的IList绑定到一个gridview。 IList中包含其他自定义的IList。我需要从这个IList的一个属性绑定到GridView。

I'm having trouble figuring out how to bind a custom IList to a gridview. The IList contains another custom IList. I need to bind a property from this IList to the gridview.

public class Seminar : BusinessObject
{
    private string _description = String.Empty;
    private List<User> _attendees;

    public string Description {get {return _description;} set {_description = value;}}
    public List<User> Attendees {get {return _attendees;} set {_attendees = value;}}
}

public class User : BusinessObject
{
    private string _name = String.Empty;
    public string Name { get { return _name; } set { _name = value; } }
}

后端page.aspx.cs:

Backend page.aspx.cs:

List<Seminar> seminarList = SeminarManager.Get(id);
gridSeminars.DataSource = seminarList;
gridSeminars.DataBind();

前端pa​​ge.aspx:

Frontend page.aspx:

<asp:GridView ID="gridSeminars" runat="server">
<Columns>
    <asp:BoundField DataField="Id" />
    <asp:BoundField DataField="Description" />
    <asp:BoundField DataField="Name" />
</Columns>
</asp:GridView>

问题是在GridView填充名称字段。所有建议都欢迎。

The problem is with populating the "Name" field in the gridview. All suggestions are welcome.

推荐答案

你有没有试过,

Attendees.Name

编辑:
与会者是一个IEnumerable本身。以上建议仅适用于Attendee.Name

Attendees is an IEnumerable itself. The above suggestion only works with Attendee.Name

如果您wan't显示你需要做一个TemplateField的所有与会者,也许使用一个中继器或东西...是这样的:

If you wan´t to display all the attendees you need to make a templatefield and maybe use a repeater or something...something like:

   <asp:TemplateField>
        <ItemTemplate>
            <asp:Repeater runat="server" DataSource='<%# Eval("Attendees") %>'>
                <ItemTemplate>
                    <tr>
                    <td>
                    Name
                    </td>
                    <td>
                        <%# Eval("Name")%>
                    </td>
                    </tr>
                </ItemTemplate>
            </asp:Repeater>
        </ItemTemplate>
    </asp:TemplateField>

这篇关于GridView的绑定到IList&LT;&BusinessObject的GT;包含一个IList&LT;&BusinessObject的GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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