1 Solution
Hello Guiem,
I see that you forgot to add ASPxDataView into a form. Please modify your code, as shown below:
[C#]ASPxDataView dv = new ASPxDataView(); form1.Controls.Add(dv); dv.ItemTemplate = new MyItemTemplate(); dv.DataSource = sQueries.DameQuejasSector(sesion, 1); // my query... dv.DataBind();
-
[DX Support team: Posted by Guiem Julià]
Hello Marion,
thank you for your answer. I forgot to give you more info in the ticket. I didn't add the ASPxDataView to a form because I add it to an ASPxPageControl. So my code is:
int page= 0;
XPCollection<Sector> sectores = new XPCollection<Sector>(sesion);
foreach (Sector sector in sectores)
{
ASPxPageControlSectores.TabPages.Add(sector.Nombre, sector.Oid.ToString());
ASPxDataView dv = new ASPxDataView();
ASPxPageControlSectores.TabPages[pagina].Controls.Add(dv);
dv.ItemTemplate = new MyItemTemplate();
dv.DataSource = sQueries.DameQuejasSector(sesion, sector.Oid);
dv.DataBind();
pagina++;
}
So I have a loop for a XPCollection, for each item I create a new TabPages, a new DataView and I add the DataView to the new TabPages. If I do like this I have the problem of TemplateControl=null.
Thank you
-
If you add a control into a container, it is necessary to create a container hierarchy first. For example:
for (int i = 0; i < 5; i++) { ASPxPageControlSectores.TabPages.Add("Nombre" + i, "Oid" + i); } ASPxPageControlSectores.DataBind();I have attached a sample project that illustrates this solution. Please check it.
-
Thank you Marion. ASPxPageControlSectores.DataBind(); solves the problem. I didn't know I must databind the aspxpagecontrol too.
Best regards,
Guiem -
@Guiem, you are always welcome!
Is your intention to post an answer to your own question?
- If so, then proceed.
- If you simply wanted to post additional information, ask for further clarification, or to just say "Thanks!", please click Leave a Comment.
- If you wish to edit your original question, please use the Edit button in the Toolbox at the top right corner of that entry.