Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > LLBLGen Pro Runtime Framework> DropDownList and Sorting using Adapter
 

Pages: 1
LLBLGen Pro Runtime Framework
DropDownList and Sorting using Adapter
Page:1/1 

  Print all messages in this thread  
Poster Message
TonyLacey
User



Location:
Albany, NY
Joined on:
11-Mar-2008 15:45:59
Posted:
15 posts
# Posted on: 28-Mar-2008 16:20:21.  
Hi,

First of all... Using 2.5 Final Demo version (you should be getting money any day for real version... I only have 5 days left on DEMO!!!!)... and I like it alot. Thank you. I came from NetTiers and liked that too but yours works with DB2, which I need to support.

.Net 3.5 and ASP.NET...

My question is... What is the easiest way to sort the items in a dropdownlist. I have it bound to a LLBLGenProDataSource2. What I have is a FormView with a bunch of fields.. 10 being dropdownlists to FK of other EntityCollections. For example, one of the fields is Employee... and I list all available employees... How can I EASILY Regular Smiley sort the employees by UFullname?

Thanks!
Tony


  Top
Walaa
Support Team



Location:

Joined on:
21-Aug-2005 16:03:48
Posted:
14464 posts
# Posted on: 28-Mar-2008 16:29:01.  
For each dropdownlist set its LLBLGenProDataSource.SorterToUse to the required sortExpression.

  Top
TonyLacey
User



Location:
Albany, NY
Joined on:
11-Mar-2008 15:45:59
Posted:
15 posts
# Posted on: 28-Mar-2008 16:50:28.  
Thank you Walaa for fast response!

That is what I thought but when I do this I get the following error.

Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.

Could be I'm just not thinking right. Wink     Also, are there any plans to add an OrderByClause to DataSource? so I can do...

Code:

<llblgenpro:LLBLGenProDataSource2 ID="caretakerDataSource" runat="server" AdapterTypeName="InventoryDAL.DatabaseSpecific.DataAccessAdapter, InventoryDALDBSpecific" DataContainerType="EntityCollection" EntityFactoryTypeName="InventoryDAL.FactoryClasses.UserEntityFactory, InventoryDAL"
OrderByClause="UFullname, UAge">
</llblgenpro:LLBLGenProDataSource2>


without adding anything to code behind? This would be awesome!



Here is problem aspx:
Code:
<asp:DropDownList ID="caretakerDropDownList" runat="server" AppendDataBoundItems="true" DataSourceID="caretakerDataSource" DataTextField="UFullname" DataValueField="UId" SelectedValue='<%# Eval("ICaretakerId") %>'>
     <asp:ListItem Value="">Unassigned</asp:ListItem>
</asp:DropDownList>&nbsp;&nbsp;<asp:ImageButton ID="addUserButton1" runat="server" AlternateText="Add New User" ImageUrl="~/Images/new.jpg" OnClick="addUserClick" />
<llblgenpro:LLBLGenProDataSource2 ID="caretakerDataSource" runat="server" AdapterTypeName="InventoryDAL.DatabaseSpecific.DataAccessAdapter, InventoryDALDBSpecific" DataContainerType="EntityCollection" EntityFactoryTypeName="InventoryDAL.FactoryClasses.UserEntityFactory, InventoryDAL">
</llblgenpro:LLBLGenProDataSource2>



and problem Code behind:
Code:
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Session["EditIId"] == null)
                {
                    // Inserting new inventory....
                    FormView1.DefaultMode = FormViewMode.Insert;
                }
                else
                {
                    if (Session["ReadOnly"] == null)
                        FormView1.DefaultMode = FormViewMode.Edit;
                    else
                        FormView1.DefaultMode = FormViewMode.ReadOnly;
                    InventoryDataSource.PrefetchPathToUse = new PrefetchPath2((int)EntityType.InventoryEntity);
                    InventoryDataSource.PrefetchPathToUse.Add(InventoryEntity.PrefetchPathRoom);
                    InventoryDataSource.PrefetchPathToUse.Add(InventoryEntity.PrefetchPathCategory);
                    InventoryDataSource.PrefetchPathToUse.Add(InventoryEntity.PrefetchPathSubcategory);
                    InventoryDataSource.PrefetchPathToUse.Add(InventoryEntity.PrefetchPathCaretakerUser);
                    InventoryDataSource.PrefetchPathToUse.Add(InventoryEntity.PrefetchPathDisposalApprovedByUser);
                    InventoryDataSource.PrefetchPathToUse.Add(InventoryEntity.PrefetchPathInstalledByUser);

                    LLBLGenProDataSource2 ds = (LLBLGenProDataSource2)FormView1.FindControl("caretakerDataSource");
                    SortExpression sort = new SortExpression(UserFields.UFullname | SortOperator.Ascending);
                    ds.SorterToUse = sort;
                }
            }
        }




Thanks again,
Tony

  Top
goose
User



Location:
Central America
Joined on:
06-Aug-2007 18:21:05
Posted:
385 posts
# Posted on: 29-Mar-2008 19:13:46.  
Seems like the exception originates in this part of your code:

Code:
... SelectedValue='<%# Eval("ICaretakerId") ...


Please double check the full stack trace of your exception.


gansodesoya  Top
TonyLacey
User



Location:
Albany, NY
Joined on:
11-Mar-2008 15:45:59
Posted:
15 posts
# Posted on: 01-Apr-2008 20:00:13.  
Thanks Goose.


Here is the Exception. The weird part about this is everything works fine and the dropdownlist is populated fine without those 3 lines of code I added to sort. But with the three lines I get what is below...    So those three lines I added IS the official way to add sorting to each dropdownlist?

Quote:
Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.

Source Error:

Line 58:                             </td>
Line 59:                             <td>
Line 60:                                 <asp: DropDownList ID="caretakerDropDownList" runat="server" AppendDataBoundItems="true"
Line 61:                                     DataSourceID="caretakerDataSource" DataTextField="UFullname"
Line 62:                                     DataValueField="UId" SelectedValue='<%# Eval("ICaretakerId") %>'>


Source File: c:\MyFiles\DotNet 2008\inventory\InventoryApp\InventoryApp\admin\inventoryEdit.aspx    Line: 60

Stack Trace:

[InvalidOperationException: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.]
System.Web.UI.Page.GetDataItem() +2049122
System.Web.UI.TemplateControl.Eval(String expression) +111
ASP.admin_inventoryedit_aspx.__DataBinding__control7(Object sender, EventArgs e) in c:\MyFiles\DotNet 2008\inventory\InventoryApp\InventoryApp\admin\inventoryEdit.aspx:60
System.Web.UI.Control.OnDataBinding(EventArgs e) +99
System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e) +11
System.Web.UI.WebControls.ListControl.PerformSelect() +31
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +70
System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82
System.Web.UI.WebControls.ListControl.OnPreRender(EventArgs e) +26
System.Web.UI.Control.PreRenderRecursiveInternal() +86
System.Web.UI.Control.PreRenderRecursiveInternal() +170
System.Web.UI.Control.PreRenderRecursiveInternal() +170
System.Web.UI.Control.PreRenderRecursiveInternal() +170
System.Web.UI.Control.PreRenderRecursiveInternal() +170
System.Web.UI.Control.PreRenderRecursiveInternal() +170
System.Web.UI.Control.PreRenderRecursiveInternal() +170
System.Web.UI.Control.PreRenderRecursiveInternal() +170
System.Web.UI.Control.PreRenderRecursiveInternal() +170
System.Web.UI.Control.PreRenderRecursiveInternal() +170
System.Web.UI.Control.PreRenderRecursiveInternal() +170
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2041



THANKS!
Tony

  Top
Walaa
Support Team



Location:

Joined on:
21-Aug-2005 16:03:48
Posted:
14464 posts
# Posted on: 02-Apr-2008 11:18:13.  
I remember seeing this bug before, it has nothing to do with LLBLGen Pro, it occurs in rare cases when binding a DropDownList control inside a FormView.
And it has something to do with switching the views of a Form view from code behind.

I don't remember exactly the resolution, but would you please try the following code.

Quote:
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Session["EditIId"] == null)
                {
                    // Inserting new inventory....
                    FormView1.DefaultMode = FormViewMode.Insert;
                    FormView1.ChangeMode(FormViewMode.Insert);
                }
                else
                {
                    if (Session["ReadOnly"] == null)
                    {
                        FormView1.DefaultMode = FormViewMode.Edit;
                        FormView1.ChangeMode(FormViewMode.Edit);
                    }
                    else
                    {
                        FormView1.DefaultMode = FormViewMode.ReadOnly;
                        FormView1.ChangeMode(FormViewMode.ReadOnly);
                    }

                    InventoryDataSource.PrefetchPathToUse = new PrefetchPath2((int)EntityType.InventoryEntity);
                    InventoryDataSource.PrefetchPathToUse.Add(InventoryEntity.PrefetchPathRoom);
                    InventoryDataSource.PrefetchPathToUse.Add(InventoryEntity.PrefetchPathCategory);
                    InventoryDataSource.PrefetchPathToUse.Add(InventoryEntity.PrefetchPathSubcategory);
                    InventoryDataSource.PrefetchPathToUse.Add(InventoryEntity.PrefetchPathCaretakerUser);
                    InventoryDataSource.PrefetchPathToUse.Add(InventoryEntity.PrefetchPathDisposalApprovedByUser);
                    InventoryDataSource.PrefetchPathToUse.Add(InventoryEntity.PrefetchPathInstalledByUser);

                    LLBLGenProDataSource2 ds = (LLBLGenProDataSource2)FormView1.FindControl("caretakerDataSource");
                    SortExpression sort = new SortExpression(UserFields.UFullname | SortOperator.Ascending);
                    ds.SorterToUse = sort;
                }
                //FormView1.DataBind();// you might need this line too
            }
        }


  Top
TonyLacey
User



Location:
Albany, NY
Joined on:
11-Mar-2008 15:45:59
Posted:
15 posts
# Posted on: 02-Apr-2008 15:23:05.  
Thanks alot Walaa. You are certainly correct that is has nothing to do with LLBLGen. I did a search on that error and found tons of hits.. I tried what you suggested and I got the same error unfortunately. I tried a few of the other suggestions on others sites and still get the same error. So now that I know at least I'm doing it the correct way in terms of LLBLGen... I'll make it work some way. It's just weird that I don't get the error until I insert that sorting code.

I appreciate your time VERY much! Take care.

LLBLGen: Still would like my OrderByClause="UFullname, UAge" property! Wink

Thank you,
Tony

  Top
raist
User



Location:
Madrid, Spain
Joined on:
19-Apr-2010 23:57:10
Posted:
114 posts
# Posted on: 08-Jul-2011 18:27:41.  
System.Web.UI.Control.FindControl not always works.
The easiest way I have found (v.3.1 on .Net 2.0):

Code:
<llblgenpro:LLBLGenProDataSource ID="_SupplierDS" ... OnLoad="setSorter"/>

NOTE: SortingMode="ServerSide" (Default)

Code Behind:

Code:
    protected void setSorter(object sender, EventArgs e)
    {
            LLBLGenProDataSource ds = (LLBLGenProDataSource)sender;
            SortExpression sort = new SortExpression(SupplierFields.CompanyName | SortOperator.Ascending);
            ds.SorterToUse = sort;
    }


  Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.