The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

esDataSource & ListView

Last post 07-22-2008, 6:51 AM by Mike.Griffin. 9 replies.
Sort Posts: Previous Next
  •  07-19-2008, 3:22 PM 10305

    esDataSource & ListView

    I'm using ES 2008.1.623.0 with ASP.NET 3.5.

    I don't understand what I'm doing wrong. In the following code I use a ListView with esDataSource

     

    Code:
    <asp:ListView ID="ListView1" DataSourceID="esdTest" runat="server">
                <LayoutTemplate>
                    <div>
                        <asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
                    </div>
                </LayoutTemplate>
                <ItemTemplate>
                    <%# Eval("HotelName") %><br />
                </ItemTemplate>
    </asp:ListView>
    <cc1:esDataSource ID="esdTest" runat="server" />
    
    
    Private Sub esdTest_esSelect(ByVal sender As Object, ByVal e As EntitySpaces.Web.esDataSourceSelectEventArgs) Handles esdTest.esSelect
    
            Dim coll As New HotelViewCollection
            Dim item As New HotelView
    
            item = coll.AddNew
            item.HotelName = "Test 1"
            item = coll.AddNew
            item.HotelName = "Test 2"
    
            e.Collection = coll
    
    End Sub

     This code produces the following error:

     

    Code:
    [InvalidCastException: Cast specificato non valido.]
       EntitySpaces.Web.esDataSourceView.FetchTotalRowCount(esDataSourceSelectEventArgs e) +447
       EntitySpaces.Web.esDataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +276
       System.Web.UI.WebControls.DataBoundControl.PerformSelect() +142
       System.Web.UI.WebControls.ListView.PerformSelect() +57
       System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73
       System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82
       System.Web.UI.WebControls.ListView.CreateChildControls() +55
       System.Web.UI.Control.EnsureChildControls() +87
       System.Web.UI.Control.PreRenderRecursiveInternal() +44
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842
    

     

    But If I don't use the esDataSource in this way:

    Code:
            <asp:ListView ID="ListView1" runat="server">
                <LayoutTemplate>
                    <div>
                        <asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
                    </div>
                </LayoutTemplate>
                <ItemTemplate>
                    <%# Eval("HotelName") %><br />
                </ItemTemplate>
            </asp:ListView>
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
            Dim coll As New HotelViewCollection
            Dim item As New Viagiar.Business.Objects.HotelView
    
            item = coll.AddNew
            item.HotelName = "Test 1"
            item = coll.AddNew
            item.HotelName = "Test 2"
    
            ListView1.DataSource = coll
            ListView1.DataBind()
    
        End Sub
    All work fine
  •  07-19-2008, 3:35 PM 10306 in reply to 10305

    Re: esDataSource & ListView

    Why are you adding things in your select event? Have a look at the sample I posted here for approprate usage of the esDataSource with the ListView.

    Regards,

    Scott Schecter
    EntitySpaces | My Site
  •  07-19-2008, 3:56 PM 10308 in reply to 10306

    Re: esDataSource & ListView

    Thanks Scott, I'm adding things in select event only for test purpose, normally I use EntitySpaces like the example you posted. I tried again with another collection and without the datapager but the error is always the same. With the others controls (Gridview, Repeater, ...) no problem

     

  •  07-19-2008, 4:11 PM 10309 in reply to 10308

    Re: esDataSource & ListView

    Well the point is you can't change the row count in the esSelect event as we need to know it for proper paging. You can try setting AutoPaging="False" on the esDataSource, but you still really shouldn't be adding thing manually in the esSelect event. If you look at our esDataSource samples in our FAQ section you will see that adding/editing/deleting is tracked for you automatically and you should not be doing it manually.

    Regards,

    Scott Schecter
    EntitySpaces | My Site
  •  07-19-2008, 4:14 PM 10310 in reply to 10308

    Re: esDataSource & ListView

    Well the point is you shouldn't change the row count in the esSelect event as we need to know it for paging. You can try setting AutoPaging="False" on the esDataSource, but you still really shouldn't be adding thing manually in the esSelect event. If you look at our esDataSource samples in our FAQ section you will see that adding/editing/deleting is tracked for you automatically and you should not be doing it manually as this is what the esCreateEntity event is for.

     

    Code:
    protected void EsDataSource1_esCreateEntity(object sender, EntitySpaces.Web.esDataSourceCreateEntityEventArgs e)
    {
    	Employees employee = new Employees();
    	if (e.PrimaryKeys == null)
    	{
    		employee.AddNew();
    	}
    	else
    	{
    		employee.LoadByPrimaryKey((int)e.PrimaryKeys[0]);
    	}
    
    	e.Entity = employee;
    }
     
    Regards,

    Scott Schecter
    EntitySpaces | My Site
  •  07-19-2008, 4:20 PM 10311 in reply to 10309

    Re: esDataSource & ListView

    Ok Scott maybe this example can helps :

     

    Code:
     <asp:ListView ID="ListView1" DataSourceID="esdTest" runat="server">
                <LayoutTemplate>
                    <div>
                        <asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
                    </div>
                </LayoutTemplate>
                <ItemTemplate>
                    <%# Eval("CountryId") %><br />
                </ItemTemplate>
            </asp:ListView>
    <cc1:esDataSource ID="esdTest" AutoPaging="False" runat="server" />
    
        Private Sub esdTest_esSelect(ByVal sender As Object, ByVal e As EntitySpaces.Web.esDataSourceSelectEventArgs) Handles esdTest.esSelect
    
            Dim query As New CityQuery
            query.OrderBy(query.CountryId.Ascending)
    
            e.Collection = New CityCollection
            e.Query = query
    
        End Sub
     Error doesn't change.
  •  07-19-2008, 4:27 PM 10312 in reply to 10311

    Re: esDataSource & ListView

    Well then you don't have something configured correctly. For instance I don't see the DataKeyNames property set on your ListView which should be set automatically for you if you are configuring both the esDataSource and your databound control via the smart tags. You need to look at the sample I posted and linked to to see what you are doing differently.

    Regards,

    Scott Schecter
    EntitySpaces | My Site
  •  07-20-2008, 2:47 PM 10315 in reply to 10312

    Re: esDataSource & ListView

    Also, it could be that calling AddNew() in the esSelect event is the issue, if you are bound to a control then calling AddNew on the esCollection (or esDataSource) will sent events to back the control, the control then turns around and calls esSelect again, it could be recursion issue? Populate your collection before esSelect and try it.

    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  07-22-2008, 5:28 AM 10324 in reply to 10315

    Re: esDataSource & ListView

    Hi Mike,

    I tried to populate the collection before esSelect but the error continues. If I set the TotalRowCount manually all work. I don't know why in FetchTotalRowCount the argument RetrieveTotalRowCount is always set to True If I don't want to use the Datapager.

    Thank you for your help

  •  07-22-2008, 6:51 AM 10330 in reply to 10324

    Re: esDataSource & ListView

    I think we can address this in our 1st maintenance release. Let me first verify that we are auto fetching the row count if AutoPaging is false, if so, we will fix this, thanx for the post.


    EntitySpaces | Twitter | BLOG | Please honor our Software License
View as RSS news feed in XML