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.E
private List&User& _
public string Description {get {return _} set {_description =}}
public List&User& Attendees {get {return _} set {_attendees =}}
public class User : BusinessObject
private string _name = String.E
public string Name { get { return _ } set { _name = } }
Backend page.aspx.cs:
List&Seminar& seminarList = SeminarManager.Get(id);
gridSeminars.DataSource = seminarL
gridSeminars.DataBind();
Frontend page.aspx:
&asp:GridView ID="gridSeminars" runat="server"&
&asp:BoundField DataField="Id" /&
&asp:BoundField DataField="Description" /&
&asp:BoundField DataField="Name" /&
&/Columns&
&/asp:GridView&
The problem is with populating the "Name" field in the gridview. All suggestions are welcome.
解决方案 Have you tried,
Attendees.Name
Attendees is an IEnumerable itself. The above suggestion only works with Attendee.Name
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&
&%# Eval("Name")%&
&/ItemTemplate&
&/asp:Repeater&
&/ItemTemplate&
&/asp:TemplateField&
本文地址: &
我在遇到麻烦找出如何自定义的IList绑定到一个gridview。 IList中包含其他自定义的IList。我需要从这个IList的一个属性绑定到GridView。 公共类研讨会:BusinessObject的{
私人字符串_description =的String.E
私人列表&使用者> _
公共字符串描述{{返回_}集合{_description =值;}}
公开名单&使用者>与会者{{返回_}集合{_attendees =值;}}}公共类用户:BusinessObject的{
私人字符串_name =的String.E
公共字符串名称{{返回_ }集合{_name =价值; }}} 后端page.aspx.cs: 列表<研讨会暨GT; seminarList = SeminarManager.Get(ID);gridSeminars.DataSource = seminarLgridSeminars.DataBind(); 前端page.aspx: < ASP:GridView控件ID =“gridSeminars”=“服务器”><柱体和GT;
< ASP:BoundField的数据字段=“ID”/>
< ASP:BoundField的数据字段=“说明”/>
< ASP:BoundField的数据字段=“名称”/>< /专栏>< / ASP:GridView的> 问题是在GridView填充“名称”字段。所有建议都欢迎。 解决方案 你有没有试过,
Attendees.Name
编辑:与会者是一个IEnumerable本身。以上建议仅适用于Attendee.Name 如果您wan't显示你需要做一个TemplateField的所有与会者,也许使用一个中继器或东西...是这样的: < ASP:的TemplateField>
<&ItemTemplate中GT;
< ASP:直放站=“服务器”数据源='<%#的eval(“与会者”)%>'>
<&ItemTemplate中GT;
&所述; TR>
&所述; TD>
< / TD>
&所述; TD>
<%#的eval(“姓名”)%>
< / TD>
< / TR>
< / ItemTemplate中>
< / ASP:直放站>
< / ItemTemplate中>
< / ASP:的TemplateField>
本文地址: &
扫一扫关注官方微信}