Problem with LLBLGenProDataSource2

Posts   
 
    
sgentile
User
Posts: 2
Joined: 25-Jul-2007
# Posted on: 25-Jul-2007 22:33:47   

Hi, I would like to bind a collection to the gridview on an aspx page. I do not want to bind directly to the adapter but return the collection from an intermediate layer. I had no problem binding the gridview to an IList<T> but I can't use nor paging nor sorting without writing lots' of extra code. I tried then to recurr at the LLBLGenProDataSource2 to witch I pass my EntityCollection. Like

LLBLGenProDataSource2_1.LivePersistence = false; LLBLGenProDataSource2_1.DataContainerType = DataSourceDataContainerType.EntityCollection; LLBLGenProDataSource2_1.EnablePaging = true; LLBLGenProDataSource2_1.EntityCollection=value; GridView1.DataSource = LLBLGenProDataSource2_1; GridView1.DataBind();

Now the error I get at the Gridview1.DataBind is that the collection is readonly. What am I doing wrong? Is there a better way to obtain this?

Thanks

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 26-Jul-2007 09:11:41   

For LivePersistence = false, you should handle 3 events. PerformSelect. This event is raised when the LLBLGenProDataSource2 control needs to retrieve data from the database. PerformGetDbCount. This event is raised when the LLBLGenProDataSource2 control needs to retrieve the number of items in the complete resultset. This event is raised when server side paging is enabled and the total number of items in the resultset is required by the bound control(s). PerformWork. This event is raised when ExecuteInsert/Update/Delete is called on the LLBLGenProDataSource2 control by a bound control. Typically this is done after an entity is edited in a GridView or FormView control for example, or a new entity is added through a bound control. The work is tracked in a UnitOfWork2 object which is available to you in the event arguments.

sgentile
User
Posts: 2
Joined: 25-Jul-2007
# Posted on: 26-Jul-2007 09:42:45   

Here are my 3 methods: protected void LLBLGenProDataSource2_1_PerformSelect(object sender, PerformSelectEventArgs2 e) { LLBLGenProDataSource2_1.EntityCollection = _listaDocs; LLBLGenProDataSource2_1.DataBind(); } protected void LLBLGenProDataSource2_1_PerformWork(object sender, PerformWorkEventArgs2 e) {

    }
    protected void LLBLGenProDataSource2_1_PerformGetDbCount(object sender, PerformGetDbCountEventArgs2 e)
    {
       e.DbCount= _listaDocs.Count;
    }

As I have understood the LLBLGenProDataSource2 can work in disconnected mode like the dataset. What I need is just a gridview where I can page and sort the (not much) data collection without changing any data. For this reason I left the the performwork method empty. But I still get an error with the binding (Collection is readonly) Another thing I still do not understand is if I must bind the datasource before binding to the grid so I also tried this in the inizializer part: public EntityCollection<PubblicazioneEntity> ListaDocs {

        set
        {
            _listaDocs = value;
            System.Diagnostics.Debug.Write(value.Count);
            BuildGrid();
            LLBLGenProDataSource2_1.DataContainerType = DataSourceDataContainerType.EntityCollection;
            LLBLGenProDataSource2_1.LivePersistence = false;
            LLBLGenProDataSource2_1.EnablePaging = true;
            LLBLGenProDataSource2_1.EntityCollection = _listaDocs;
            LLBLGenProDataSource2_1.DataBind();
            GridView1.DataSource = LLBLGenProDataSource2_1;
            GridView1.DataBind();
        }
    }

I'd like if you could give me (or point me to) any examples where all the code and binding is done in code behind. As I said I need the Disconnected-ReadOnly mode but I think that it would be useful also the Connected mode. I'm also trying to use the Model View Presenter pattern and in this pattern there is no direct connection to the Model (where I suppose the DataAccessAdapter belongs) so the indirection from the aspx page (the view) it is very important.

Thanks

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 26-Jul-2007 10:00:43   

But I still get an error with the binding (Collection is readonly)

In the Perform Select event, don't set the LLBLGenProDataSource2_1.EntityCollection Instead set the e.ContainedCollection

Another thing I still do not understand is if I must bind the datasource before binding to the grid so I also tried this in the inizializer part:

No you don't have to.

I'd like if you could give me (or point me to) any examples where all the code and binding is done in code behind.

Did you check the Examples on the downloads section of llblgenpro website?