1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / UserControl and Repeater Templates for news

UserControl and Repeater Templates for news

3 posts, 0 answered
  1. Pierre
    Pierre avatar
    433 posts
    Registered:
    16 Feb 2006
    22 Apr 2009
    Link to this post
    Hi,

    I have one UserControl that implement one Designer. The main user control get
    the News items using ContentManager IContent server side. In this UC I add another Usercontrol as template in one divtemplate. The second usercontrol added is the template to write the results and contains one Reapeater with news items.
    If my dataset is in main usercontrol and the repeater is in child usercontrol how to pass the values from main uc to child uc and be able to access using <%Eval%> expressions.? 
    Adding the template as usercontrol is the right way?

    Thanks for your help.
  2. Ivan
    Ivan avatar
    478 posts
    Registered:
    16 Jun 2015
    22 Apr 2009
    Link to this post
    Hi Pierre,

    Eval is used to evaluate expressions and since it seems you are binding complex data from your top level repeater to the user control in the item template of the repeater, you will not be able to use eval.

    However, there is a very simple approach to this.
    - in your top level repeater create an event handler for the ItemDataBound event
    - in the ItemDataBound event find the user control in the template
    - set the data to the user control you've found
    - trigger the data binding in the nested user control

    Is this a good approach? Well, it really depends. If you are working with complex nested layouts it might be. But also, you may want to check out the ListView control which is very flexible, yet more powerful than Repeater.

    I hope you'll find this information helpful. Let us know if there is anything else we can do for you.

    Sincerely yours,
    Ivan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Pierre
    Pierre avatar
    433 posts
    Registered:
    16 Feb 2006
    22 Apr 2009
    Link to this post

    Hi Ivan,

    ListView is not very usefull for me, my data are the metafileds. I lovely implement another solution more easier like ViewManager proposed by Scott Guthrie .

    public class ViewManager  
    {  
        public static string RenderView(string path)  
        {  
            return RenderView(path, null);  
        }  
     
        public static string RenderView(string path, object data)  
        {  
            Page pageHolder = new Page();  
            UserControl viewControl = (UserControl) pageHolder.LoadControl(path);  
     
            if (data != null)  
            {  
                Type viewControlviewControlType = viewControl.GetType();              
                FieldInfo field = viewControlType.GetField("Data");  
     
                if (field != null)  
                {  
                    field.SetValue(viewControl, data);  
                }  
                else  
                {  
                    throw new Exception("View file: " + path + " does not have a public Data property");  
                }  
            }  
     
            pageHolder.Controls.Add(viewControl);  
     
            StringWriter output = new StringWriter();  
            HttpContext.Current.Server.Execute(pageHolder, output, false);  
     
            return output.ToString();  
        }  

    In this ViewManager working similar as MVC, I need to expose the Icontent Items of ContentManager as "object Data" to link after the template. Could you suggest how to cast the Icontent items to one object Data to be able to use this method? or modify to use the Icontent as source.

    Thanks. 

Register for webinar
3 posts, 0 answered