Binding Generic Collections to an ASP.GridView
-
Hi, I have a generic object of type List<Items> with a sub collection of objects of type List<Descriptions>. I want to bind them to a gridview but not sure if it's possible, I have tried binding only the object of type List<Items> but if I try adding an ItemTemplate with another grid to try to bind the object of type List<Descriptions> i'm getting an error. says "it should implement IDatasource." something. my column structure in the grid would look like this.
<Columns>
<asp:BoundField DataField="Key" HeaderText="Key" SortExpression="Key" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:TemplateField HeaderText="Descriptions" HeaderStyle-CssClass="headerstyle">
<ItemTemplate>
<asp:GridView ID="gv_descriptions" runat="server" DataSourceID='<%# DataBinder.Eval(Container.DataItem, "Descriptions") %>' AutoGenerateColumns="false"
AllowPaging="true" EnableViewState="false" BorderStyle="None" GridLines="None" ShowEmptyTable="true" AllowSorting="true">
<Columns>
<asp:BoundField DataField="Description" HeaderText="ShortDescription" SortExpression="ShortDescription" />
</Columns>
</asp:GridView>
</ItemTemplate>
</asp:TemplateField>
</Columns> -
Hi, I have a generic object of type List<Items> with a sub collection of objects of type List<Descriptions>. I want to bind them to a gridview but not sure if it's possible, I have tried binding only the object of type List<Items> but if I try adding an ItemTemplate with another grid to try to bind the object of type List<Descriptions> i'm getting an error. says "it should implement IDatasource." something. my column structure in the grid would look like this.
<Columns>
<asp:BoundField DataField="Key" HeaderText="Key" SortExpression="Key" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:TemplateField HeaderText="Descriptions" HeaderStyle-CssClass="headerstyle">
<ItemTemplate>
<asp:GridView ID="gv_descriptions" runat="server" DataSourceID='<%# DataBinder.Eval(Container.DataItem, "Descriptions") %>' AutoGenerateColumns="false"
AllowPaging="true" EnableViewState="false" BorderStyle="None" GridLines="None" ShowEmptyTable="true" AllowSorting="true">
<Columns>
<asp:BoundField DataField="Description" HeaderText="ShortDescription" SortExpression="ShortDescription" />
</Columns>
</asp:GridView>
</ItemTemplate>
</asp:TemplateField>
</Columns>Handle the
RowDataBound
event, find the nestedGridView
and bindList<Descriptions>
.Navaneeth How to use google | Ask smart questions
-
Hi, I have a generic object of type List<Items> with a sub collection of objects of type List<Descriptions>. I want to bind them to a gridview but not sure if it's possible, I have tried binding only the object of type List<Items> but if I try adding an ItemTemplate with another grid to try to bind the object of type List<Descriptions> i'm getting an error. says "it should implement IDatasource." something. my column structure in the grid would look like this.
<Columns>
<asp:BoundField DataField="Key" HeaderText="Key" SortExpression="Key" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:TemplateField HeaderText="Descriptions" HeaderStyle-CssClass="headerstyle">
<ItemTemplate>
<asp:GridView ID="gv_descriptions" runat="server" DataSourceID='<%# DataBinder.Eval(Container.DataItem, "Descriptions") %>' AutoGenerateColumns="false"
AllowPaging="true" EnableViewState="false" BorderStyle="None" GridLines="None" ShowEmptyTable="true" AllowSorting="true">
<Columns>
<asp:BoundField DataField="Description" HeaderText="ShortDescription" SortExpression="ShortDescription" />
</Columns>
</asp:GridView>
</ItemTemplate>
</asp:TemplateField>
</Columns>dear while binding grid you must be doing some thing like.. grid.datasource = obj so this obj is not iEnumerable or idatasource might be you changing generic with something else.. type here obj.tolist() to make it ienumerable...
Government Dyal Singh College Lahore.