Sort dropdownlist bound to LLBLGenProDataSource

Posts   
 
    
Rhywun avatar
Rhywun
User
Posts: 44
Joined: 05-Jan-2005
# Posted on: 27-Jun-2006 18:55:33   

Maybe I'm dense this morning--also I haven't been able to use LLBL in about 6 months--but I can't figure out how to sort a bound dropdownlist, on a custom field that I added to my entity. I'm using .NET 2.0 with the LLBL v2 beta. I've managed to get the dropdownlist working and displaying my custom field, but now I want to sort it.

The help file states in regard to two-way databinding: "By default no filter is set, no groupby, no prefetch path, no sorting. The DefaultView() object is returned from the entity collection embedded in the datasourcecontrol. To set a filter, prefetch path or sortexpression, a code behind page is required to set these parameters."

But I can't find out 1) where (which event) to add sorting code, nor 2) how to do it.

Please help! Thanks

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39590
Joined: 17-Aug-2003
# Posted on: 28-Jun-2006 12:35:05   

Set the property SortingMode to ClientSide, and add a sortexpression which sorts on the custom property to the datasourcecontrol in your code behind. This way the sort expression you specify will be used clientside as the sorter of the entityview returned from the data in the datasourcecontrol, which thus means it will sort the data on your custom property.

Create the sortclause of your custom property as: // C# sortExpression.Add((new EntityProperty("CustomFieldName") | SortOperator.Ascending);

// VB.NET, adapter sortExpression.Add(New SortClause(New EntityProperty("CustomFieldName"), Nothing, SortOperator.Ascending))

// VB.NET, selfservicing sortExpression.Add(New SortClause(New EntityProperty("CustomFieldName"), SortOperator.Ascending))

Frans Bouma | Lead developer LLBLGen Pro
Rhywun avatar
Rhywun
User
Posts: 44
Joined: 05-Jan-2005
# Posted on: 28-Jun-2006 19:19:33   

Otis wrote:

Set the property SortingMode to ClientSide, and add a sortexpression which sorts on the custom property to the datasourcecontrol in your code behind. This way the sort expression you specify will be used clientside as the sorter of the entityview returned from the data in the datasourcecontrol, which thus means it will sort the data on your custom property.

Create the sortclause of your custom property as: // C# sortExpression.Add((new EntityProperty("CustomFieldName") | SortOperator.Ascending);

// VB.NET, adapter sortExpression.Add(New SortClause(New EntityProperty("CustomFieldName"), Nothing, SortOperator.Ascending))

// VB.NET, selfservicing sortExpression.Add(New SortClause(New EntityProperty("CustomFieldName"), SortOperator.Ascending))

Sorry, I need a little more help simple_smile Or I need to walk through it a little more slowly. Or maybe I'm going about this the wrong way...

Let's say I have an entity MyEntity with database fields Id, LastName and FirstName. I have added this property myself to the generated entity class:


public string FullName {
    get {
        return LastName + ", " + FirstName;
    }
}

Now I have a FormView and in the Edit- and InsertItemTemplates I have DropDownLists and LLBLGenProDataSources. I am able to populate the DropDownList by setting my data source and setting DataValueField to "Id" and DataTextField to "FullName". But now I want to sort.

Unfortunately, I don't understand what you mean by "add a sortexpression which sorts on the custom property to the datasourcecontrol in your code behind". I got as far as


protected void Page_Load(object sender, EventArgs e)
{
    ISortExpression sortExpression = new SortExpression(new EntityProperty("FullName") | SortOperator.Ascending);
    dataSource1.EntityCollection.SortClauses = sortExpression;
}

but I get an error 'dataSource1 does not exist in the current context'. Obviously I'm doing something wrong simple_smile

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39590
Joined: 17-Aug-2003
# Posted on: 28-Jun-2006 20:34:39   

WHat's the name of your LLBLGenProDataSource(2) control in your webform?

Frans Bouma | Lead developer LLBLGen Pro
Rhywun avatar
Rhywun
User
Posts: 44
Joined: 05-Jan-2005
# Posted on: 28-Jun-2006 21:59:18   

Otis wrote:

WHat's the name of your LLBLGenProDataSource(2) control in your webform?

It's actually called 'insertPreparerDataSource'. It's inside an 'InsertItemTemplate' in the FormView.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39590
Joined: 17-Aug-2003
# Posted on: 28-Jun-2006 22:13:58   

Rhywun wrote:

Otis wrote:

WHat's the name of your LLBLGenProDataSource(2) control in your webform?

It's actually called 'insertPreparerDataSource'. It's inside an 'InsertItemTemplate' in the FormView.

Then it should be: insertPreparerDataSource.SorterToUse = sortExpression;

so you set the sorter on the datasource.

Frans Bouma | Lead developer LLBLGen Pro
Rhywun avatar
Rhywun
User
Posts: 44
Joined: 05-Jan-2005
# Posted on: 28-Jun-2006 23:18:07   

Otis wrote:

Rhywun wrote:

Otis wrote:

WHat's the name of your LLBLGenProDataSource(2) control in your webform?

It's actually called 'insertPreparerDataSource'. It's inside an 'InsertItemTemplate' in the FormView.

Then it should be: insertPreparerDataSource.SorterToUse = sortExpression;

so you set the sorter on the datasource.

Sounds good. Sorry to be a pest, but one more question: How do I refer to the data source in code? This must be an issue with FormView, but I can't find any documentation on how to get a reference to a control inside a FormView.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39590
Joined: 17-Aug-2003
# Posted on: 29-Jun-2006 00:39:33   

Well, avoid placing datasource controls INSIDE other controls, that's unnecessary, just place them on the form outside other controls. Then you should be able to refer to them by using the ID simple_smile

Frans Bouma | Lead developer LLBLGen Pro
like2175
User
Posts: 83
Joined: 27-Mar-2006
# Posted on: 29-Jun-2006 09:11:23   

Am I correct to say that LLBLGenProDataSource control is only available from version 2.0 of LLBLGenPro?

If they are available in v1 then how do I get to the position where I can drag one onto my form?

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 29-Jun-2006 09:32:03   

LLBLGenProDataSource is available only on LLBLGen Pro v.2

Rhywun avatar
Rhywun
User
Posts: 44
Joined: 05-Jan-2005
# Posted on: 29-Jun-2006 16:53:15   

Otis wrote:

Well, avoid placing datasource controls INSIDE other controls, that's unnecessary, just place them on the form outside other controls. Then you should be able to refer to them by using the ID simple_smile

Yeah - I thought of that simple_smile

OK, I have moved all datasources outside the FormView. We are almost there - but the following code:

protected void Page_Load(object sender, EventArgs e)
{
    ISortExpression sortExpression = new SortExpression(new EntityProperty("FullName") | SortOperator.Ascending);
    insertPreparerDataSource.SorterToUse = sortExpression;
}

results in this error:

[SerializationException: Type 'SD.LLBLGen.Pro.ORMSupportClasses.EntityProperty' in Assembly 'SD.LLBLGen.Pro.ORMSupportClasses.NET20, Version=2.0.0.0, Culture=neutral, PublicKeyToken=ca73b74ba4e3ff27' is not marked as serializable.]
... 
[ArgumentException: Error serializing value 'SD.LLBLGen.Pro.ORMSupportClasses.SortExpression' of type 'SD.LLBLGen.Pro.ORMSupportClasses.SortExpression.']

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39590
Joined: 17-Aug-2003
# Posted on: 29-Jun-2006 20:35:01   

Whoops! bug. Will fix this. That doesn't solve your problem of course. I havent checked but isn't there a sorting property on the combobox control?

Frans Bouma | Lead developer LLBLGen Pro
Rhywun avatar
Rhywun
User
Posts: 44
Joined: 05-Jan-2005
# Posted on: 29-Jun-2006 22:03:11   

Otis wrote:

isn't there a sorting property on the combobox control?

Not that I know of. No big deal - I can wait for a bugfix simple_smile

Rhywun avatar
Rhywun
User
Posts: 44
Joined: 05-Jan-2005
# Posted on: 19-Sep-2006 23:14:43   

Hi - the same code is giving me a different error after running the Sept. 8, 2006 release of the designer. The error appears on line 49:

Source Error: 


Line 47:        public bool GetMultiAsDataTable(IEntityFields fieldsToReturn, DataTable tableToFill, long maxNumberOfItemsToReturn, ISortExpression sortClauses, IPredicate selectFilter, IRelationCollection relations, bool allowDuplicates, IGroupByCollection groupByClause, ITransaction transactionToUse, int pageNumber, int pageSize)
Line 48:        {
Line 49:            return base.PerformGetMultiAsDataTableAction(fieldsToReturn, tableToFill, maxNumberOfItemsToReturn, sortClauses, selectFilter, relations, allowDuplicates, groupByClause, transactionToUse, pageNumber, pageSize);
Line 50:        }
Line 51:        


Source File: ...\DaoClasses\TypedListDAO.cs Line: 49 

Stack Trace: 


[Exception: The method or operation is not implemented.]
   SD.LLBLGen.Pro.ORMSupportClasses.EntityProperty.get_AggregateFunctionToApply() +46
   SD.LLBLGen.Pro.ORMSupportClasses.SortExpression.ToQueryText(Int32& uniqueMarker, Boolean aliasesForExpressionsAggregates) +136
   SD.LLBLGen.Pro.ORMSupportClasses.SortExpression.ToQueryText(Int32& uniqueMarker) +9
   SD.LLBLGen.Pro.ORMSupportClasses.DynamicQueryEngineBase.AppendOrderByClause(StringBuilder queryText, ISortExpression sortClauses, IDbCommand cmd) +108
   SD.LLBLGen.Pro.DQE.SqlServer.DynamicQueryEngine.CreateSelectDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, IDbConnection connectionToUse, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause, Boolean relationsSpecified, Boolean sortClausesSpecified) +2224
   SD.LLBLGen.Pro.ORMSupportClasses.DynamicQueryEngineBase.CreateSelectDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, IDbConnection connectionToUse, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause) +258
   SD.LLBLGen.Pro.DQE.SqlServer.DynamicQueryEngine.CreatePagingSelectDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, IDbConnection connectionToUse, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause, Int32 pageNumber, Int32 pageSize) +118
   SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.CreateQueryFromElements(ITransaction transactionToUse, IEntityFields fields, IPredicate filter, IRelationCollection relations, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, IGroupByCollection groupByClause, Boolean allowDuplicates, Int32 pageNumber, Int32 pageSize) +468
   SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.PerformGetMultiAsDataTableAction(IEntityFields fieldsToReturn, DataTable tableToFill, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPredicate selectFilter, IRelationCollection relations, Boolean allowDuplicates, IGroupByCollection groupByClause, ITransaction transactionToUse, Int32 pageNumber, Int32 pageSize) +102
   TowerGroup.TowerApps.QCTrack.Business.DaoClasses.TypedListDAO.GetMultiAsDataTable(IEntityFields fieldsToReturn, DataTable tableToFill, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPredicate selectFilter, IRelationCollection relations, Boolean allowDuplicates, IGroupByCollection groupByClause, ITransaction transactionToUse, Int32 pageNumber, Int32 pageSize) in C:\Documents and Settings\PHuffer\My Documents\Visual Studio 2005\Projects\TowerGroup\TowerApps\QCTrack\Business\DaoClasses\TypedListDAO.cs:49
   TowerGroup.TowerApps.QCTrack.Business.TypedViewClasses.AllIssuersTypedView.Fill(Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, Boolean allowDuplicates, IPredicate selectFilter, ITransaction transactionToUse, IGroupByCollection groupByClause, Int32 pageNumber, Int32 pageSize) in C:\Documents and Settings\PHuffer\My Documents\Visual Studio 2005\Projects\TowerGroup\TowerApps\QCTrack\Business\TypedViewClasses\AllIssuersTypedView.cs:209
   SD.LLBLGen.Pro.ORMSupportClasses.LLBLGenProDataSourceView.ExecuteSelectTypedView(Int32 pageSize, Int32 pageNumber, DataSourceSelectArguments arguments) +380
   SD.LLBLGen.Pro.ORMSupportClasses.LLBLGenProDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +148
   System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e) +82
   System.Web.UI.WebControls.ListControl.PerformSelect() +18
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +68
   System.Web.UI.Control.DataBindChildren() +214
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +208
   System.Web.UI.Control.DataBind() +12
   System.Web.UI.Control.DataBindChildren() +214
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +208
   System.Web.UI.Control.DataBind() +12
   System.Web.UI.Control.DataBindChildren() +214
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +208
   System.Web.UI.Control.DataBind() +12
   System.Web.UI.Control.DataBindChildren() +214
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +208
   System.Web.UI.Control.DataBind() +12
   System.Web.UI.Control.DataBindChildren() +214
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +208
   System.Web.UI.WebControls.FormView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) +2182
   System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +59
   System.Web.UI.WebControls.FormView.PerformDataBinding(IEnumerable data) +10
   System.Web.UI.WebControls.FormView.EnsureDataBound() +112
   System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +67
   System.Web.UI.Control.EnsureChildControls() +97
   System.Web.UI.Control.PreRenderRecursiveInternal() +50
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5706
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39590
Joined: 17-Aug-2003
# Posted on: 20-Sep-2006 09:31:58   

What does that EntityProperty Instance doing in your fields list? That's for in-memory operations only. simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Rhywun avatar
Rhywun
User
Posts: 44
Joined: 05-Jan-2005
# Posted on: 20-Sep-2006 20:54:50   

Otis wrote:

What does that EntityProperty Instance doing in your fields list? That's for in-memory operations only. simple_smile

Because I was using a custom property? That's what you told me to do above simple_smile

But your question reminds me that I'm not using a custom property any more - I'm using a typed view instead. So just now I replaced

new EntityProperty("FullName")

with

AllProofreadersFields.FullName

and it works! (My view is named "AllProofreaders"). Thanks.

Charlie
User
Posts: 8
Joined: 27-Oct-2006
# Posted on: 27-Oct-2006 14:58:47   

I have the following code set up to sort three dropdownlists. The field to sort by is entitled 'name' in all 3 cases so I have used one sort expression.


        'Sort the Ward's DDL
        Dim sortExpression As New SortExpression
        sortExpression.Add(New SortClause(New EntityProperty("name"), SortOperator.Ascending))

        LLBLDataWard.SorterToUse = sortExpression

        'Sort the Dept DDL
        LLBLDataWard.SorterToUse = sortExpression

        'Sort the Party DDL
        LLBLDataWard.SorterToUse = sortExpression

However when this is run the sortExpression.add line causes the following error:

Unable to cast object of type 'SD.LLBLGen.Pro.ORMSupportClasses.EntityProperty' to type 'SD.LLBLGen.Pro.ORMSupportClasses.IEntityField'.

Any ideas?

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 28-Oct-2006 04:11:20   

Try switching on clientside sorting for this, as serverside sorting on entity properties not in the entity target table isn't possible. clientside sorting is a flag on the datasource control