DataList in Gridview
-
Hi, I have the complex business object like: Ownership. Ownership object is collection of buisness objects, collection of person objects. class Ownership { Collection<BusinessData> Businesses; Collection<PersonData> Persons; } In the ASPX.cs Page_Load I am adding the business objects to Ownership object: OwnerShip owners = new OwnerShip(); owners.Businesses.Add(new BusinessData("XX LLC", true, 0, 20, "pres", "", true)); XX LLC is business name. owners.Businesses.Add(new BusinessData("YY LLP", false, 0, 20, "vice president", "", true)); In ASPx page it is like this: <asp:GridView ID="gvOwners" runat="server" AutoGenerateColumns="False" Width="787px" OnRowDataBound="gvOwners_RowDataBound"> <Columns> asp:TemplateField <ItemTemplate> <asp:DataList ID="BusinessPersonDataList" runat="server"> <ItemTemplate> <%# ((BusinessDescriptionData)Container.DataItem).BusinessName %> </ItemTemplate> </asp:DataList> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> Now in the RowDatabound event of GridView, I want to bind one DataList with Business colection.(in another DataList I want to bind the Persons collection, I did not put the code for this part yet. First I am trying with the Busienss objects). The RowDataBound event is like trhe below: protected void gvOwners_RowDataBound(object sender, GridViewRowEventArgs e) { OwnerShip os = null; GridViewRow r = e.Row; if (r.DataItem != null) // Make sure we're not in the Header or Footer row { os = r.DataItem as OwnerShip; } DataList BPDataList = e.Row.FindControl("BusinessPersonDataList") as DataList; if (BPDataList != null && os != null) { BPDataList.DataSource = os.Businesses; BPDataList.DataBind(); } } When I run the page, I am not getting any results. The Gridview is not displaying anything. If I remove the RowDatabound event and in the page_load gvOwners.DataSource = owners.Businesses; I have not used the datalist in this example, just binded to one Label in Gridview. Then it is displaying the results. I think the RowDatabound event is not firing. What is the problem in the above? Thanks in advance.
-
Hi, I have the complex business object like: Ownership. Ownership object is collection of buisness objects, collection of person objects. class Ownership { Collection<BusinessData> Businesses; Collection<PersonData> Persons; } In the ASPX.cs Page_Load I am adding the business objects to Ownership object: OwnerShip owners = new OwnerShip(); owners.Businesses.Add(new BusinessData("XX LLC", true, 0, 20, "pres", "", true)); XX LLC is business name. owners.Businesses.Add(new BusinessData("YY LLP", false, 0, 20, "vice president", "", true)); In ASPx page it is like this: <asp:GridView ID="gvOwners" runat="server" AutoGenerateColumns="False" Width="787px" OnRowDataBound="gvOwners_RowDataBound"> <Columns> asp:TemplateField <ItemTemplate> <asp:DataList ID="BusinessPersonDataList" runat="server"> <ItemTemplate> <%# ((BusinessDescriptionData)Container.DataItem).BusinessName %> </ItemTemplate> </asp:DataList> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> Now in the RowDatabound event of GridView, I want to bind one DataList with Business colection.(in another DataList I want to bind the Persons collection, I did not put the code for this part yet. First I am trying with the Busienss objects). The RowDataBound event is like trhe below: protected void gvOwners_RowDataBound(object sender, GridViewRowEventArgs e) { OwnerShip os = null; GridViewRow r = e.Row; if (r.DataItem != null) // Make sure we're not in the Header or Footer row { os = r.DataItem as OwnerShip; } DataList BPDataList = e.Row.FindControl("BusinessPersonDataList") as DataList; if (BPDataList != null && os != null) { BPDataList.DataSource = os.Businesses; BPDataList.DataBind(); } } When I run the page, I am not getting any results. The Gridview is not displaying anything. If I remove the RowDatabound event and in the page_load gvOwners.DataSource = owners.Businesses; I have not used the datalist in this example, just binded to one Label in Gridview. Then it is displaying the results. I think the RowDatabound event is not firing. What is the problem in the above? Thanks in advance.
You need to put break points and step into the code to know what's going wrong.
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions