performselect question

Posts   
 
    
bunzee
User
Posts: 84
Joined: 20-Mar-2007
# Posted on: 27-Feb-2008 00:19:15   

Hi

I notice the following in this forum:

  1. In thread http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=10463&HighLight=1, it is recommended to use
e.ContainedCollection.Clear();
e.ContainedCollection.Add(myEmployeeFromWS);
  1. In another thread http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=9797&HighLight=1, it is recommened
adapter.FetchEntityCollection(e.ContainedCollection, e.Filter, e.MaxNumberOfItemsToReturn, Sorter, e.PrefetchPath, e.PageNumber, e.PageSize)
  1. And in here http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=6855&HighLight=1 we have
 _ordersDS.EntityCollection = _customer.Orders;

Question: When should we use <datasource>.EntityCollection and when should we use <PerformWorkEventArgs2>.ContainedCollection? What are the pros and cons in each?

Thanks

BZ

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 27-Feb-2008 10:09:36   

Both are the same. As e.ContainedCollection refers to the DataSource.EntityCollection.

bunzee
User
Posts: 84
Joined: 20-Mar-2007
# Posted on: 28-Feb-2008 19:20:30   

Thanks. I have one more question.

There are times where I have a gridview bind to an llblgen datasource and I don't want to define the ds_PerformSelect routine even when livepersistence of the llblgen datasource object is set to false. What I ended up doing is in another some other routine such as a button click event I have

ds.EntityCollection = MyBllRoutineThatFetchAnEntityCollection

What I ended up having to do is to define the ds_PerformSelect routine and stick the ds.EntityCollection = MyBllRoutineThatFetchAnEntityCollection code in the PerformSelect routine.

What I notice is that gridview does not display the entity collection set. On the other hand, if I use TypedList instead of Entity (i.e. ds.TypedList = MyBllRoutineThatFetchATypeList) then the gridview displays properly.

BTW, the gridview and llblgen datasource all have the default settings as far as "enabling viewstate is concern".

So it seemed to me that some how with EntityCollection the gridview won't bind to the datasource when the button click event occurred. With TypeList then gridview bind just fine.

Is this easy to follow or must I create an example and post it up?

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 29-Feb-2008 09:05:04   

In the button click event you should call gridView1.DataBind()And in the PerformSelect event, you should set the EntityCollection of the dataSource to the return of MyBllRoutineThatFetchAnEntityCollection()

bunzee
User
Posts: 84
Joined: 20-Mar-2007
# Posted on: 05-Mar-2008 21:15:06   

Walaa,

Thanks for the response. However I think the approach you suggested will not work in my case because I use the later DataSourceId property of the gridview instead of the older DataSource and DataBind code behind approach.

Below are my findings and my questions:


IN ASCX FILE
<llblgenpro:LLBLGenProDataSource2 ID="ldsNdcLabelname" runat="server" AdapterTypeName="MW.DAL.DatabaseSpecific.DataAccessAdapter, MW.DALDBSpecific" CacheLocation="Session" DataContainerType="TypedList"
                                    LivePersistence="False" OnPerformSelect="ldsNdcLabelname_PerformSelect" >
                                </llblgenpro:LLBLGenProDataSource2>
...
<asp:GridView ID="gvNdcLabelname" runat="server" AllowPaging="True" AutoGenerateColumns="False"
                                        DataKeyNames="LabelName" DataSourceID="ldsNdcLabelname" OnPageIndexChanged="gvNdcLabelname_PageIndexChanged"
                                        OnSelectedIndexChanging="gvNdcLabelname_SelectedIndexChanging" Visible="true" OnPageIndexChanging="gvNdcLabelname_PageIndexChanging"
                                        BorderColor="Silver" >
...


IN CS FILE
...
private NdcDistinctLabelnameTypedList _ndcTypedList;
...
public void DisplayLabelnamesSearched(NdcDistinctLabelnameTypedList ndcs)
{
        _ndcTypedList = ndcs;
        gvNdcLabelname.DataBind();
}
...
protected void ldsNdcLabelname_PerformSelect(object sender, PerformSelectEventArgs2 e)
{
        ldsNdcLabelname.TypedList = _ndcTypedList;
}

With the above code behind .cs file, the gridview never shows the fetched typedlist.


IN CS FILE
...
private NdcDistinctLabelnameTypedList _ndcTypedList;
...
public void DisplayLabelnamesSearched(NdcDistinctLabelnameTypedList ndcs)
{
        _ndcTypedList = ndcs;
        ldsNdcLabelname_PerformSelect();
}
...
protected void ldsNdcLabelname_PerformSelect(object sender, PerformSelectEventArgs2 e)
{
        ldsNdcLabelname.TypedList = _ndcTypedList;
}

With the above code behind the ldsNdcLabelname_PerformSelect() got invoked twice after it is called by DisplayLabelnamesSearched routine the first time the DisplayLabelnamesSearched is called. By the way, DisplayLabelnamesSearched() is invoked by a button click event.

So basically here's what happended:

formload button click DisplayLabelnamesSearched() ldsNdcLabelname_PerformSelect() ldsNdcLabelname_PerformSelect() ... a second button click

DisplayLabelnamesSearched() ldsNdcLabelname_PerformSelect()

QUESTIONS: Does any one know why the ldsNdcLabelname_PerformSelect() got invoked 2x? Further more, the in the second time that ldsNdcLabelname_PerformSelect() got invoked (first button click), the ldsNdcLabelname.TypedList.Count went back to zero. I wonder why? Basically what happened is that when a function invoked the PerformSelect() routine manually, it is being invoked twice (must be due to some sort of behind the scene binding with the gridview) and the second time around the ldsNdcLabelname.TypedList was reset so the count is zero. Why?

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 06-Mar-2008 10:43:44   

PerformSelect is an event and shouldn't be called, rather try to call the datasource.Select()

Please try the following code (also try it with LivePersistence="True"):

public void DisplayLabelnamesSearched(NdcDistinctLabelnameTypedList ndcs)
{
        ldsNdcLabelname.TypedList = ndcs;
        gvNdcLabelname.DataSource = ldsNdcLabelname; // this line may not be used.
        gvNdcLabelname.DataBind();
}

or this one:

public void DisplayLabelnamesSearched(NdcDistinctLabelnameTypedList ndcs)
{
        _ndcTypedList = ndcs;
        ldsNdcLabelname.Select();
}
...
protected void ldsNdcLabelname_PerformSelect(object sender, PerformSelectEventArgs2 e)
{
        ldsNdcLabelname.TypedList = _ndcTypedList;
}
bunzee
User
Posts: 84
Joined: 20-Mar-2007
# Posted on: 17-Apr-2008 19:30:15   

Thanks Walaa,

Your method almost work. The only thing is I need to add refetch=true in order for the performselect method to get invoked.


public void DisplayLabelnamesSearched(NdcDistinctLabelnameTypedList ndcs)
{
        _ndcTypedList = ndcs;
        ldsNdcLabelname.Refetch = true;
        ldsNdcLabelname.Select();
}
...
protected void ldsNdcLabelname_PerformSelect(object sender, PerformSelectEventArgs2 e)
{
        ldsNdcLabelname.TypedList = _ndcTypedList;
}