[CLOSED] DataView [0.8.1] The Template can't be empty

  1. #1

    [CLOSED] DataView [0.8.1] The Template can't be empty

    Hi,

    I have the following code. Mainly I am trying to display something like this: https://examples1.ext.net/#/TreePane...age_Organizer/

    I am making an Image Viewer. So this is the way I am filling up the thumbnail panel.

    What I am doing wrong?

    
    cimages is a list of an object composed of and  image URL and a Name.
    
    DataView dataview = new DataView();
    Store store = new Store();
    store.DataSource = cimages;
    store.DataBind();
    XTemplate xTemplate = new XTemplate();
    xTemplate.CustomConfig.Add(new ConfigItem("html", "['<ul class=\"\">','<tpl for=\".\">','<li><div class=\"\"><img src=\"{Url}\"></div><span>{Name}</span></li>','</tpl>','</ul>','']", ParameterMode.Raw));
    dataview.Template.Text =  xTemplate.Text;
    dataview.StoreID = store.ID;
    dataview.ItemSelector = "div";
    dataview.StyleSpec = "overflow:auto";
    dataview.MultiSelect = true;
    _leftPanel.Items.Add(dataview);
    I am getting this error: The Template can't be empty
    Last edited by geoffrey.mcgill; Jul 26, 2010 at 6:32 AM.
  2. #2
    Hi,

    When I run your code sample I get an Exception. Did you copy that code sample from the Examples Explorer? If yes, can let me know which code sample you got it from.
    Geoffrey McGill
    Founder
  3. #3

    Re

    Hi,

    Ive added the source code of the control (Ive deleted the Coolite references to make it "light" v0.8.1). Also, to make it work you need an empty website with the following code on the the load method, and of course a folder on the given path and a couple of images.

     
    string s = @"C:\path1";
            List<string > ls =new List<string>();
            ls.Add("image1.jpg");
            ls.Add("image2.jpg");
            ImageViewer.ImageViewer civ = new ImageViewer.ImageViewer(s,ls);
            civ.Width = 600;
            civ.Height = 350;
            civ.Show();
    Btw This is a work in progress. Ive just started it, so if theres another good idea on how to display thumbnails it would be helpfull.

    P.D. Can you erase the duplicated post "DataView [0.8.1] The Template can't be empty " on Help Forums. Ty.
    Attached Files
  4. #4
    Hi,

    You have to set own template to the Text (Html in the 1.0) property of the XTemplate
     dataview.Template.Text = "<ul class=\"\"><tpl for=\".\"><li><div class=\"\"><img src=\"{Url}\"></div><span>{Name}</span></li></tpl></ul>";
  5. #5

    Re

    Changed to:

    dataview.Template.Text = "<ul class=\"\"><tpl for=\".\"><li><div class=\"\"><img src=\"{Url}\"></div></li></tpl></ul>";
    Still receiving the same error:

    The Template can't be empty. Parameter name: Template
  6. #6
    Hi,

    I modified your class as suggested and don't have that error. Please provide test page which uses your ImageViewer
    Here is my test case
    <%@ Page Language="C#" %>
    <%@ Import Namespace="Coolite.Ext.Web" %>
    <%@ Import Namespace="System.Collections.Generic" %>
    <%@ Import Namespace="System.IO" %>
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        
        <script runat="server">
            public class VwImage
            {
                public Coolite.Ext.Web.Image Image { get; set; }
                public string Url { get; set; }
                public string Name { get; set; }
                public string OriginalUrl { get; set; }
            }
    
            public class ImageViewer : Window
            {
                #region variables
    
                private Coolite.Ext.Web.Panel _leftPanel = new Coolite.Ext.Web.Panel();
                private Coolite.Ext.Web.Panel _southPanel = new Coolite.Ext.Web.Panel();
                private Coolite.Ext.Web.Panel _mainPanel = new Coolite.Ext.Web.Panel();
                private Coolite.Ext.Web.Panel _rightPanel = new Coolite.Ext.Web.Panel();
                private List<string> _imagesNames = new List<string>();
    
                #endregion
    
    
                #region Properties
    
                private Coolite.Ext.Web.Image _mainImage;
                public Coolite.Ext.Web.Image MainImage
                {
                    get
                    {
                        EnsureChildControls();
                        return _mainImage;
                    }
                    set
                    {
                        EnsureChildControls();
                        _mainImage = value;
                    }
                }
    
                private List<Coolite.Ext.Web.Image> _imagesContainer;
                public List<Coolite.Ext.Web.Image> ImagesContainer
                {
                    get
                    {
                        EnsureChildControls();
                        return _imagesContainer;
                    }
                    set
                    {
                        EnsureChildControls();
                        _imagesContainer = value;
                    }
                }
    
                private List<VwImage> _imagesThumbnailContainer;
                public List<VwImage> ImagesThumbnailContainer
                {
                    get { return _imagesThumbnailContainer; }
                    set { _imagesThumbnailContainer = value; }
                }
                private int _containerSize;
                public int ContainerSize
                {
                    get
                    {
                        EnsureChildControls();
                        return _containerSize;
                    }
                    set
                    {
                        EnsureChildControls();
                        _containerSize = value;
                    }
                }
    
                private string _path;
                public string Path
                {
                    get
                    {
                        EnsureChildControls();
                        return _path;
                    }
                    set
                    {
                        EnsureChildControls();
                        _path = value;
                    }
                }
    
    
    
                #endregion
    
                #region Constructors
    
    
                public ImageViewer(string path, List<string> imagesNames)
                {
                    try
                    {
                        if (Directory.Exists(path))
                        {
                            _path = path;
                            _containerSize = Directory.GetFiles(path).GetUpperBound(0) + 1;
                            _imagesContainer = new List<Coolite.Ext.Web.Image>();
                            _imagesNames = imagesNames;
                            foreach (var imagesInfo in Directory.GetFiles(path))
                            {
                                foreach (var imagesName in imagesNames)
                                {
                                    if (imagesInfo.Contains(imagesName))
                                    {
                                        Coolite.Ext.Web.Image image = new Coolite.Ext.Web.Image();
                                        image.ImageUrl = imagesInfo;
                                        _imagesContainer.Add(image);
                                    }
                                }
                            }
    
                            _mainImage = _imagesContainer[0];
                            _mainPanel.BodyControls.Add(_mainImage);
    
    
                            List<VwImage> cimages = new List<VwImage>();
                            foreach (var image in _imagesContainer)
                            {
                                var cimage = new VwImage();
                                cimage.Image = image;
                                cimage.Url = image.ImageUrl;
                                cimages.Add(cimage);
                            }
    
                            DataView dataview = new DataView();
                            Store store = new Store();
                            store.DataSource = cimages;
                            store.DataBind();
                            //XTemplate xTemplate = new XTemplate();
                            //xTemplate.CustomConfig.Add(new ConfigItem("html", "['<ul class=\"\">','<tpl for=\".\">','<li><div class=\"\"><img src=\"{Url}\"></div><span>{Name}</span></li>','</tpl>','</ul>','']", ParameterMode.Raw));
                            dataview.Template.Text = "<ul class=\"\"><tpl for=\".\"><li><div class=\"\"><img src=\"{Url}\"></div><span>{Name}</span></li></tpl></ul>";
                            dataview.StoreID = store.ID;
                            dataview.ItemSelector = "div";
                            dataview.StyleSpec = "overflow:auto";
                            dataview.MultiSelect = true;
                            _leftPanel.Items.Add(dataview);
                        }
                    }
                    catch (Exception ex)
                    {
                        Ext.MessageBox.Alert("ImageViewer", ex.Message);
                    }
    
                }
    
    
                #endregion
    
                #region Override
    
                public override void Show()
                {
                    InitializeWindow();
                    base.Show();
                }
    
                #endregion
    
                #region Private Methods
                private void InitializeWindow()
                {
    
                    //Panels
    
                    _southPanel.ID = "SouthPanel" + Guid.NewGuid().ToString().Substring(0, 5);
                    _southPanel.Height = Unit.Pixel(25);
                    _southPanel.BodyStyle = "padding:6px;";
    
                    _rightPanel.ID = "RightPanel" + Guid.NewGuid().ToString().Substring(0, 5);
                    _rightPanel.Width = Unit.Pixel(95);
                    _rightPanel.BodyStyle = "padding:6px;";
    
                    _leftPanel.ID = "LeftPanel" + Guid.NewGuid().ToString().Substring(0, 5);
                    _leftPanel.Width = Unit.Pixel(100);
                    _leftPanel.BodyStyle = "padding:6px;";
    
                    _mainPanel.ID = "MainPanel" + Guid.NewGuid().ToString().Substring(0, 5);
                    _mainPanel.BodyStyle = "padding:6px;";
    
                    //Buttons
    
                    var btnPrint = new Coolite.Ext.Web.Button();
                    btnPrint.ID = "btnPrint" + Guid.NewGuid().ToString().Substring(0, 5);
                    btnPrint.Text = "Print";
                    btnPrint.MinWidth = Unit.Pixel(80);
                    btnPrint.Icon = Coolite.Ext.Web.Icon.Printer;
    
                    var btnSave = new Coolite.Ext.Web.Button();
                    btnSave.ID = "btnSave" + Guid.NewGuid().ToString().Substring(0, 5);
                    btnSave.Text = "    Save";
                    btnSave.MinWidth = Unit.Pixel(80);
                    btnSave.Icon = Coolite.Ext.Web.Icon.Disk;
    
                    var btnZoomIn = new Coolite.Ext.Web.Button();
                    btnZoomIn.ID = "btnZoomIn" + Guid.NewGuid().ToString().Substring(0, 5);
                    btnZoomIn.Text = "  ZoomIn";
                    btnZoomIn.MinWidth = Unit.Pixel(80);
                    btnZoomIn.Icon = Coolite.Ext.Web.Icon.MagnifierZoomIn;
    
                    var btnZooOut = new Coolite.Ext.Web.Button();
                    btnZooOut.ID = "btnZooOut" + Guid.NewGuid().ToString().Substring(0, 5);
                    btnZooOut.Text = "  ZoomOut";
                    btnZooOut.MinWidth = Unit.Pixel(80);
                    btnZooOut.Icon = Coolite.Ext.Web.Icon.ZoomOut;
    
                    _rightPanel.BodyControls.Add(btnPrint);
                    _rightPanel.BodyControls.Add(btnSave);
                    _rightPanel.BodyControls.Add(btnZoomIn);
                    _rightPanel.BodyControls.Add(btnZooOut);
    
                    //Layout
                    var layout = new BorderLayout();
    
                    // Set West Region properties
                    layout.West.Split = true;
                    layout.West.Collapsible = true;
    
                    // Set East Region properties
                    layout.East.Split = false;
                    layout.East.Collapsible = true;
    
                    // Set South Region properties
                    layout.South.Split = false;
                    layout.South.Collapsible = false;
    
                    // Add Panels to BorderLayout Regions
                    layout.West.Items.Add(_leftPanel);
                    layout.Center.Items.Add(_mainPanel);
                    layout.East.Items.Add(_rightPanel);
                    layout.South.Items.Add(_southPanel);
    
                    // Make Window to hold everything
                    ID = "Window" + Guid.NewGuid().ToString().Substring(0, 5);
                    Title = "ImageViewer";
                    Icon = Coolite.Ext.Web.Icon.Application;
                    Plain = true;
                    Border = false;
                    BodyBorder = false;
                    Collapsible = false;
    
                    // Add BorderLayout to Window
                    Items.Add(layout);
    
                    // Add Window to Form
                    ((Page)HttpContext.Current.Handler).Page.Controls.Add(this);
                }
    
                private static System.Drawing.Image ConvertByteArrayToImage(byte[] byteArray)
                {
                    if (byteArray != null)
                    {
                        MemoryStream ms = new MemoryStream(byteArray, 0,
                                         byteArray.Length);
                        ms.Write(byteArray, 0, byteArray.Length);
                        System.Drawing.Image myImg = System.Drawing.Image.FromStream(ms);
                        ms.Close();
                        return myImg;
                    }
                    return null;
                }
    
                private static System.Drawing.Image ResizeImage(System.Drawing.Image imgToResize, System.Drawing.Size size)
                {
                    try
                    {
                        int sourceWidth = imgToResize.Width;
                        int sourceHeight = imgToResize.Height;
    
                        float nPercent = 0;
                        float nPercentW = 0;
                        float nPercentH = 0;
    
                        nPercentW = ((float)size.Width / (float)sourceWidth);
                        nPercentH = ((float)size.Height / (float)sourceHeight);
    
                        nPercent = nPercentH < nPercentW ? nPercentH : nPercentW;
    
                        int destWidth = (int)(sourceWidth * nPercent);
                        int destHeight = (int)(sourceHeight * nPercent);
    
                        System.Drawing.Bitmap b = new System.Drawing.Bitmap(destWidth, destHeight);
                        System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(b);
                        g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
    
                        g.DrawImage(imgToResize, 0, 0, destWidth, destHeight);
                        g.Dispose();
    
                        return b;
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.ToString());
                    }
                }
    
                #endregion
    
            }
    
            protected void Page_Load(object sender, EventArgs e)
            {
                this.Form.Controls.Add(new ImageViewer("", new List<string>()));
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">    
            <ext:ScriptManager ID="ScriptManagerProxy" runat="server" />
    
      
        </form>
    </body>
    </html>
  7. #7

    Re

    Hi,

    You are missing something like this on the Page Load to reproduce the error:


    string s = @"C:\folder";
    List<string > ls =new List<string>();
    ls.Add("image1.jpg");
    ls.Add("image2.jpg");
    ImageViewer.ImageViewer newImageViewer= new ImageViewer.ImageViewer(s,ls);
    newImageViewer.Width = 600;
    newImageViewer.Height = 350;
    newImageViewer.Show();
    Where folder is a valid folder on the given path and image1.jpg / image2.jpg are valid random images.
  8. #8
    Hi,

    Still cannot reproduce the issue. Please create simple test project (your previous test project doesn't contain test case), zip it and post
  9. #9

    Re

    Ok uploaded. "Thumbnail" on the left panel wont show up.

    ImageViewer.zip
  10. #10
    Hi,

    Please clarify the issue. Do You have server side exception "The Template can't be empty" or just don't see thumbnails?
    About thumbnails : you set absolute (local) path to the image (like, "c:\path\image.png"). Html image cannot work with local path, you have to use valid url (it is mean that images must be inside web application folder or use http handler which will be read image and send its content)

Similar Threads

  1. [CLOSED] Script into a DataView Template
    By FVNoel in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Apr 10, 2012, 2:55 PM
  2. [CLOSED] [1.0] DataView Template Question
    By Timothy in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Aug 08, 2010, 7:49 PM
  3. DataView [0.8.1] The Template can't be empty
    By cobiscorp in forum 1.x Help
    Replies: 1
    Last Post: Jul 21, 2010, 11:25 PM
  4. Buttons in a DataView template?
    By shaun in forum 1.x Help
    Replies: 2
    Last Post: Aug 24, 2009, 3:11 AM
  5. Replies: 0
    Last Post: Jun 26, 2009, 11:32 AM

Posting Permissions