Current filter:
                                You should refresh the page.
                                Support Center
                                0
                                  • Hello,


                                    please see the example at http://www.devexpress.com/Support/Center/Example/Details/E1433. It explains how to assign the ItemTemplate at runtime.


                                    I'm trying to do this but the difference is that my AspxDataView is also created at runtime. So I have:


                                    ASPxDataView dv = new ASPxDataView();

                                    dv.ItemTemplate = new MyItemTemplate();

                                    dv.DataSource = sQueries.DameQuejasSector(sesion, 1); // my query...

                                    dv.DataBind();


                                    When DataBind() is executed container is almost null and container.TemplateControl is null so I get an error.


                                    I see that just after dv is created its TemplateControl is null, but if I use an existing AspxDataView its properties are filled. How can I create a dataview at runtime and initialize it so then I can assign its ItemTemplate?


                                    Thank you in advance.


                                    Best regards,

                                    Guiem Julià

                                You must  log in  or  register  to leave comments

                                1 Solution

                                0

                                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.

                                • Guiem Julià 08.07.2012

                                  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!

                                You must  log in  or  register  to leave comments
                                You must  log in  or  register  to leave an answer

                                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.

                                To start a chat you should create a support ticket


                                If you need additional product information, write to us at info@devexpress.com or call us at +1 (818) 844-3383

                                FOLLOW US

                                DevExpress engineers feature-complete Presentation Controls, IDE Productivity Tools, Business Application Frameworks, and Reporting Systems for Visual Studio, along with high-performance HTML JS Mobile Frameworks for developers targeting iOS, Android and Windows Phone. Whether using WPF, Silverlight, ASP.NET, WinForms, HTML5 or Windows 8, DevExpress tools help you build and deliver your best in the shortest time possible.

                                Your Privacy - Legal Statements

                                Copyright © 1998-2013 Developer Express Inc.
                                ALL RIGHTS RESERVED
                                All trademarks or registered trademarks
                                are property of their respective owners