Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. DataList in Gridview

DataList in Gridview

Scheduled Pinned Locked Moved ASP.NET
questionsysadmindockerbusinesshelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kjosh
    wrote on last edited by
    #1

    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.

    N 1 Reply Last reply
    0
    • K kjosh

      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.

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups