Problems displaying DataView

  1. #1

    Problems displaying DataView

    This is almost driving me nuts.

    I have a simple .aspx with the following:

    <style type="text/css">
            .categories-view .link-wrap{
                float: left;
                margin: 4px;
                margin-right: 0;
                padding: 5px;
                text-align:left;
            }
    
        </style>
    
    <ext:Portlet runat="server" 
                                            ID="pletLeft" 
                                            AutoHeight="true" 
                                            Draggable="false" 
                                            Cls="categories-view"
                                            Layout="Fit"
                                            Collapsible="false">  
                                            <Content>
                                                <ext:Store runat="server" ID="storeCategories" AutoLoad="true">
                                                    <Reader>
                                                        <ext:JsonReader>
                                                            <Fields>
                                                                <ext:RecordField Name="Department"></ext:RecordField>
                                                                <ext:RecordField Name="Name"></ext:RecordField>
                                                            </Fields>
                                                        </ext:JsonReader>
                                                    </Reader>
                                                </ext:Store>
                                                <ext:DataView ID="dvCategories" runat="server"
                                                    StoreID="storeCategories"
                                                    AutoHeight="true"
                                                    MultiSelect="false"
                                                    ItemSelector="div.link-wrap"
                                                    EmptyText="No hay categorías">
                                                    <Template runat="server">
                                                        <Html>
                                                            <b>Categorías</b>
                                                            <br />
                                                            <tpl for=".">
                                                                <div class="link-wrap" id="{Department}">
                                                                    <ext:LinkButton runat="server" text="{Name}"></ext:LinkButton>                                                                
                                                                </div>
                                                            </tpl>                                                            
                                                        </Html>
                                                    </Template>
                                                </ext:DataView>  
                                            </Content>                                                                        
                                        </ext:Portlet>
    In my code behind, on the load event I call a function named "LoadCategories", where I set the datasource for the Store.

    protected void Page_Load(object sender, EventArgs e)
            {
                try
                {
                    //First, retrieve the department information
                    intDepartmentId = int.Parse(Request.QueryString.Get("id"));
                    objDepartment = objPTEntities.Departments.Where(d => d.Department1 == intDepartmentId).FirstOrDefault();
    
                    //Load the categories store for the left side pane
                    LoadCategories();
                }
                catch (PortaTui.DLL.General.ApplicationException ax)
                {
                    ErrorLog.AddEntry(ErrorLog.ErrorSource.ASPX, System.Web.HttpContext.Current.Request.Url.AbsolutePath, System.Reflection.MethodBase.GetCurrentMethod().Name, ax.ToString(), int.Parse(ax.EventId));
                    X.Msg.Show(new MessageBoxConfig
                    {
                        Title = "Error inesperado",
                        Message = "Ha ocurrido un error inesperado, por favor intente de nuevo.",
                        Buttons = MessageBox.Button.OK,
                        Icon = MessageBox.Icon.ERROR,
                        AnimEl = this.ClientID
                    });
                }
                catch (Exception ex)
                {
                    ErrorLog.AddEntry(ErrorLog.ErrorSource.ASPX, System.Web.HttpContext.Current.Request.Url.AbsolutePath, System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), 0);
                    X.Msg.Show(new MessageBoxConfig
                    {
                        Title = "Error inesperado",
                        Message = "Ha ocurrido un error inesperado, por favor intente de nuevo.",
                        Buttons = MessageBox.Button.OK,
                        Icon = MessageBox.Icon.ERROR,
                        AnimEl = this.ClientID
                    });
                }            
            }
    
    private void LoadCategories()
            {
                try
                {
                    List<object> objDepartments = new List<object>();
    
                    //Add the subdepartments of the selected department
                    foreach (Department oDepartment in objPTEntities.Departments.Where(d => d.ParentDepartment == objDepartment.Department1).OrderBy(d => d.Priority))
                    {
                        objDepartments.Add(new { Department = oDepartment.Department1.ToString(), Name = oDepartment.Name });
                    }
    
                    //Assign the datasource and bind it
                    storeCategories.DataSource = objDepartments;
                    storeCategories.DataBind();
                    dvCategories.StoreID = "storeCategories";
    
                    //Validate if categories where loaded, if not, hide the section
                    if (objDepartments.Count == 0)
                        dvCategories.Visible = false;
    
                }
                catch (PortaTui.DLL.General.ApplicationException ax)
                {
                    ErrorLog.AddEntry(ErrorLog.ErrorSource.ASPX, System.Web.HttpContext.Current.Request.Url.AbsolutePath, System.Reflection.MethodBase.GetCurrentMethod().Name, ax.ToString(), int.Parse(ax.EventId));
                    X.Msg.Show(new MessageBoxConfig
                    {
                        Title = "Error inesperado",
                        Message = "Ha ocurrido un error inesperado, por favor intente de nuevo.",
                        Buttons = MessageBox.Button.OK,
                        Icon = MessageBox.Icon.ERROR,
                        AnimEl = this.ClientID
                    });
                }
                catch (Exception ex)
                {
                    ErrorLog.AddEntry(ErrorLog.ErrorSource.ASPX, System.Web.HttpContext.Current.Request.Url.AbsolutePath, System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), 0);
                    X.Msg.Show(new MessageBoxConfig
                    {
                        Title = "Error inesperado",
                        Message = "Ha ocurrido un error inesperado, por favor intente de nuevo.",
                        Buttons = MessageBox.Button.OK,
                        Icon = MessageBox.Icon.ERROR,
                        AnimEl = this.ClientID
                    });
                }
    The "objDepartments" list gets populates successfully, however, the first times I got no error but was not being able to display any LinkButton (only a blank line), but without changing much, right now I am getting the following error:

    Click image for larger version. 

Name:	Screenshot.jpg 
Views:	120 
Size:	77.1 KB 
ID:	2251

    The DataView has implicitly and from code behind also assigned the StoreId, so what in the world am I doing wrong?!
  2. #2
    Hi,

    Try to move Store into DataView.

    Example
    <ext:DataView ...remove StoreID from here...>
        <Store>
            <ext:Store ...>
                ...
            </ext:Store>
        </Store>
    </ext:DataView>
    And use <Items> instead of <Content>.

    This can make the trick to get it working.

    Also why do you set StoreID in code behind if you set it in markup?
  3. #3
    Quote Originally Posted by Daniil View Post
    Hi,

    Try to move Store into DataView.

    Example
    <ext:DataView ...remove StoreID from here...>
        <Store>
            <ext:Store ...>
                ...
            </ext:Store>
        </Store>
    </ext:DataView>
    And use <Items> instead of <Content>.

    This can make the trick to get it working.

    Also why do you set StoreID in code behind if you set it in markup?
    Thank you for the reply Daniil.

    The fatal error is gone, however I'm back to the first issue. The values are not being displayed although the list has data. If I enter a textual hello into the html, it does get displayed, but nothing else. Here is my code:

    <ext:Portlet runat="server" 
                                            ID="pletLeft" 
                                            AutoHeight="true" 
                                            Draggable="false" 
                                            Cls="categories-view"
                                            Layout="Fit"
                                            Collapsible="false">  
                                            <Items>                                            
                                                <ext:DataView ID="dvCategories" runat="server"                                                
                                                    AutoHeight="true"
                                                    MultiSelect="false"
                                                    ItemSelector="div.link-wrap"
                                                    EmptyText="No hay categorías">
                                                    <Store>
                                                        <ext:Store runat="server" ID="storeCategories" AutoLoad="true">
                                                            <Reader>
                                                                <ext:JsonReader IDProperty="Department">
                                                                    <Fields>
                                                                        <ext:RecordField Name="Department"></ext:RecordField>
                                                                        <ext:RecordField Name="Name"></ext:RecordField>
                                                                    </Fields>
                                                                </ext:JsonReader>
                                                            </Reader>
                                                        </ext:Store>
                                                    </Store>
                                                    <Template runat="server">
                                                        <Html>
                                                            <b>Categorías</b>
                                                            <br />
                                                            <tpl for=".">
                                                                <div class="link-wrap" id="{Department}">
                                                                    Hello<ext:LinkButton runat="server" text="{Name}"></ext:LinkButton>                                                                
                                                                </div>
                                                            </tpl>                                                            
                                                        </Html>
                                                    </Template>
                                                </ext:DataView>  
                                            </Items>                                                                        
                                        </ext:Portlet>
    Code behind:

    private void LoadCategories()
            {
                try
                {
                    List<object> objDepartments = new List<object>();
    
                    //Add the subdepartments of the selected department
                    foreach (Department oDepartment in objPTEntities.Departments.Where(d => d.ParentDepartment == objDepartment.Department1).OrderBy(d => d.Priority))
                    {
                        objDepartments.Add(new { Department = oDepartment.Department1.ToString(), Name = oDepartment.Name });
                    }
    
                    //Assign the datasource and bind it
                    storeCategories.DataSource = objDepartments;
                    storeCategories.DataBind();
    
                    //Validate if categories where loaded, if not, hide the section
                    if (objDepartments.Count == 0)
                        dvCategories.Visible = false;
    
                }
                catch (PortaTui.DLL.General.ApplicationException ax)
                {
                    ErrorLog.AddEntry(ErrorLog.ErrorSource.ASPX, System.Web.HttpContext.Current.Request.Url.AbsolutePath, System.Reflection.MethodBase.GetCurrentMethod().Name, ax.ToString(), int.Parse(ax.EventId));
                    X.Msg.Show(new MessageBoxConfig
                    {
                        Title = "Error inesperado",
                        Message = "Ha ocurrido un error inesperado, por favor intente de nuevo.",
                        Buttons = MessageBox.Button.OK,
                        Icon = MessageBox.Icon.ERROR,
                        AnimEl = this.ClientID
                    });
                }
                catch (Exception ex)
                {
                    ErrorLog.AddEntry(ErrorLog.ErrorSource.ASPX, System.Web.HttpContext.Current.Request.Url.AbsolutePath, System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), 0);
                    X.Msg.Show(new MessageBoxConfig
                    {
                        Title = "Error inesperado",
                        Message = "Ha ocurrido un error inesperado, por favor intente de nuevo.",
                        Buttons = MessageBox.Button.OK,
                        Icon = MessageBox.Icon.ERROR,
                        AnimEl = this.ClientID
                    });
                }
            }
    And this is what I am getting:

    Click image for larger version. 

Name:	Screen 1.png 
Views:	134 
Size:	11.7 KB 
ID:	2274

    Click image for larger version. 

Name:	Screen 2.png 
Views:	122 
Size:	6.9 KB 
ID:	2275

    Btw, I added the store ID from both sides just to prove my point.

    Thank you for your help!
  4. #4
    Quote Originally Posted by aleonardo83 View Post
    Thank you for the reply Daniil.

    The fatal error is gone, however I'm back to the first issue. The values are not being displayed although the list has data. If I enter a textual hello into the html, it does get displayed, but nothing else. Here is my code:

    <ext:Portlet runat="server" 
                                            ID="pletLeft" 
                                            AutoHeight="true" 
                                            Draggable="false" 
                                            Cls="categories-view"
                                            Layout="Fit"
                                            Collapsible="false">  
                                            <Items>                                            
                                                <ext:DataView ID="dvCategories" runat="server"                                                
                                                    AutoHeight="true"
                                                    MultiSelect="false"
                                                    ItemSelector="div.link-wrap"
                                                    EmptyText="No hay categorías">
                                                    <Store>
                                                        <ext:Store runat="server" ID="storeCategories" AutoLoad="true">
                                                            <Reader>
                                                                <ext:JsonReader IDProperty="Department">
                                                                    <Fields>
                                                                        <ext:RecordField Name="Department"></ext:RecordField>
                                                                        <ext:RecordField Name="Name"></ext:RecordField>
                                                                    </Fields>
                                                                </ext:JsonReader>
                                                            </Reader>
                                                        </ext:Store>
                                                    </Store>
                                                    <Template runat="server">
                                                        <Html>
                                                            <b>Categorías</b>
                                                            <br />
                                                            <tpl for=".">
                                                                <div class="link-wrap" id="{Department}">
                                                                    Hello<ext:LinkButton runat="server" text="{Name}"></ext:LinkButton>                                                                
                                                                </div>
                                                            </tpl>                                                            
                                                        </Html>
                                                    </Template>
                                                </ext:DataView>  
                                            </Items>                                                                        
                                        </ext:Portlet>
    Code behind:

    private void LoadCategories()
            {
                try
                {
                    List<object> objDepartments = new List<object>();
     
                    //Add the subdepartments of the selected department
                    foreach (Department oDepartment in objPTEntities.Departments.Where(d => d.ParentDepartment == objDepartment.Department1).OrderBy(d => d.Priority))
                    {
                        objDepartments.Add(new { Department = oDepartment.Department1.ToString(), Name = oDepartment.Name });
                    }
     
                    //Assign the datasource and bind it
                    storeCategories.DataSource = objDepartments;
                    storeCategories.DataBind();
     
                    //Validate if categories where loaded, if not, hide the section
                    if (objDepartments.Count == 0)
                        dvCategories.Visible = false;
     
                }
                catch (PortaTui.DLL.General.ApplicationException ax)
                {
                    ErrorLog.AddEntry(ErrorLog.ErrorSource.ASPX, System.Web.HttpContext.Current.Request.Url.AbsolutePath, System.Reflection.MethodBase.GetCurrentMethod().Name, ax.ToString(), int.Parse(ax.EventId));
                    X.Msg.Show(new MessageBoxConfig
                    {
                        Title = "Error inesperado",
                        Message = "Ha ocurrido un error inesperado, por favor intente de nuevo.",
                        Buttons = MessageBox.Button.OK,
                        Icon = MessageBox.Icon.ERROR,
                        AnimEl = this.ClientID
                    });
                }
                catch (Exception ex)
                {
                    ErrorLog.AddEntry(ErrorLog.ErrorSource.ASPX, System.Web.HttpContext.Current.Request.Url.AbsolutePath, System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), 0);
                    X.Msg.Show(new MessageBoxConfig
                    {
                        Title = "Error inesperado",
                        Message = "Ha ocurrido un error inesperado, por favor intente de nuevo.",
                        Buttons = MessageBox.Button.OK,
                        Icon = MessageBox.Icon.ERROR,
                        AnimEl = this.ClientID
                    });
                }
            }
    And this is what I am getting:

    Click image for larger version. 

Name:	Screen 1.png 
Views:	134 
Size:	11.7 KB 
ID:	2274

    Click image for larger version. 

Name:	Screen 2.png 
Views:	122 
Size:	6.9 KB 
ID:	2275

    Btw, I added the store ID from both sides just to prove my point.

    Thank you for your help!
    Any hint/update on this? Im still having the problem, Im stucked!
  5. #5
    Hi,

    Please provide a simplified sample which we can run without any changes from our side, please see #5.B
    http://forums.ext.net/showthread.php?3440

    Just I can't see what's wrong just looking at the code.

Similar Threads

  1. Replies: 2
    Last Post: Jul 05, 2012, 8:49 AM
  2. [CLOSED] DataView to DataView Drag and Drop
    By paulc in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: May 10, 2012, 8:19 PM
  3. [CLOSED] DataView displaying null
    By SouthDeveloper in forum 1.x Legacy Premium Help
    Replies: 10
    Last Post: Feb 25, 2011, 9:02 AM
  4. Problems displaying examples
    By welberger in forum Examples and Extras
    Replies: 2
    Last Post: Nov 30, 2009, 9:08 AM
  5. Displaying Images from DataBase in DataView
    By designworxz in forum 1.x Help
    Replies: 0
    Last Post: Apr 16, 2009, 8:55 PM

Posting Permissions