Drop-Down List on FormView Update

Posts   
 
    
Posts: 24
Joined: 19-Feb-2007
# Posted on: 06-Mar-2007 20:50:19   

Hi,

The problem I'm having is similar to the one addressed in this thread:

http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=8256

However, I'm having a problem with the update using a FormView. The code is:



<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="City.aspx.cs" Inherits="Admin_City" Title="Untitled Page" %>

<%@ Register Assembly="SD.LLBLGen.Pro.ORMSupportClasses.NET20" Namespace="SD.LLBLGen.Pro.ORMSupportClasses"
    TagPrefix="llblgenpro" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <asp:FormView ID="fvCity" runat="server" DataKeyNames="CityId" DataSourceID="LLBLGenProDataSource1">
        <EditItemTemplate>
            
            <table class="CanyonDigital">
                <tr class="RowStyle">
                    <td class="HeaderStyle">
                        City:
                    </td>
                    <td>
                        <asp:TextBox ID="City" runat="server" Text='<%# Bind("City") %>'>
                        </asp:TextBox>
                    </td>
                </tr>
                <tr class="RowStyle">
                    <td class="HeaderStyle">
                        State:
                    </td>
                    <td>
                        <asp:DropDownList ID="stateID" runat="server" DataSourceID="llblgenDS2" DataTextField="state" DataValueField="stateID" AutoPostBack="True" SelectedValue='<%# Bind("StateId") %>'>
                        </asp:DropDownList>
                        <llblgenpro:LLBLGenProDataSource id="llblgenDS2" runat="server" DataContainerType="EntityCollection"
                            EntityCollectionTypeName="DAL.CollectionClasses.StateCollection, App_Code.i0dy4x_t">
                        </llblgenpro:LLBLGenProDataSource>
                    </td>
                </tr>
                <tr class="RowStyle">
                    <td class="HeaderStyle">
                        County:
                    </td>
                    <td>
                        <asp:DropDownList ID="countyID" runat="server" DataSourceID="llblgenDS3" DataTextField="county" DataValueField="countyID" SelectedValue='<%# Bind("CountyId") %>' EnableViewState="false">
                        </asp:DropDownList>
                        <llblgenpro:LLBLGenProDataSource id="llblgenDS3" runat="server" DataContainerType="EntityCollection"
                            EntityCollectionTypeName="DAL.CollectionClasses.CountyCollection, App_Code.i0dy4x_t">
                            <selectparameters>
                                <asp:ControlParameter PropertyName="SelectedValue" Name="StateId" ControlID="stateID"></asp:ControlParameter>
                            </selectparameters>
                        </llblgenpro:LLBLGenProDataSource>
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:Button ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
                            Text="Update">
                        </asp:Button>
                    </td>
                </tr>
            </table>  
        </EditItemTemplate>
    </asp:FormView>
    <llblgenpro:LLBLGenProDataSource id="LLBLGenProDataSource1" runat="server" DataContainerType="EntityCollection" EntityCollectionTypeName="DAL.CollectionClasses.CityCollection, App_Code.sbnhhox3" >
        <selectparameters>
            <asp:QueryStringParameter Name="CityId" QueryStringField="cityID"></asp:QueryStringParameter>
        </selectparameters>
    </llblgenpro:LLBLGenProDataSource>
</asp:Content>



I want the State Drop-Down to filter what Counties display in the drop-down below it. The page loads properly (displaying the city/state/county) I am editing, but if I change the State drop-down, I get the error: "System.InvalidOperationException: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control."

I think it has to do with SelectedValue because if I take that part out, it works without error, however, it doesn't bind the data in when the page is loaded, nor does it put those values into the Database when the update is fired.

Any help would be greatly appreciated...simple_smile

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 07-Mar-2007 08:53:45   

Which runtimeLibrary version/buildnr are you using? http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=7717

Posts: 24
Joined: 19-Feb-2007
# Posted on: 07-Mar-2007 18:12:13   

Using version: 2.0.07.0122 Also using SQL Server 2000 Self-Servicing

Thanks.

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 08-Mar-2007 09:14:22   

Make sure your application is using the latest/newest runtimeLibrary, as sometimes the VS keep refering to older versions of the referenced assmblies.

Use the following code to test the version used:

string version = SD.LLBLGen.Pro.ORMSupportClasses.RuntimeLibraryVersion.Version + "." + 
    SD.LLBLGen.Pro.ORMSupportClasses.RuntimeLibraryVersion.Build;
Posts: 24
Joined: 19-Feb-2007
# Posted on: 08-Mar-2007 20:40:31   

Used your code and got the following result: 2.0.0.0.01222007

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 09-Mar-2007 11:23:12   

It might sound silly, but could you move the datasourcecontrols OUT of the edit template and in the main page code (not the masterpage, just out of the formview code). I think it's one of the many asp.net miseries when it comes to databinding. The thing is that when you auto-postback a combo box, the datasources will refetch and rebind but the evaluation of the controls can be postponed till the template is done... (I'm thinking out loud here but I think that's it).

Frans Bouma | Lead developer LLBLGen Pro
Posts: 24
Joined: 19-Feb-2007
# Posted on: 09-Mar-2007 20:36:39   

Still No Luck. I got this error when I tried to move it outside the FormView:


Could not find control 'stateID' in ControlParameter 'StateId'. 
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: Could not find control 'stateID' in ControlParameter 'StateId'.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace: 


[InvalidOperationException: Could not find control 'stateID' in ControlParameter 'StateId'.]
   System.Web.UI.WebControls.ControlParameter.Evaluate(HttpContext context, Control control) +1675488
   System.Web.UI.WebControls.Parameter.UpdateValue(HttpContext context, Control control) +46
   System.Web.UI.WebControls.ParameterCollection.UpdateValues(HttpContext context, Control control) +103
   SD.LLBLGen.Pro.ORMSupportClasses.LLBLGenProDataSourceBase.OnPageLoadComplete(Object sender, EventArgs e) +43
   System.EventHandler.Invoke(Object sender, EventArgs e) +0
   System.Web.UI.Page.OnLoadComplete(EventArgs e) +2012808
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1209




Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 10-Mar-2007 12:03:41   

Hmm, ok, that's caused by ASP.NET's stupid way to get access to controls so indeed that's not going to work.

I still think the datasourcecontrols have to be placed somewhere where they're initialized first. For example at the top of the template in the formview, I'm not sure. What I can't understand is why ASP.NET gives the weird error you received in your startpost... as the datasourcecontrols just return data on request.

THe select parameter makes the datasourcecontrol be refreshed with new data and signal that to the bound control. I think that gives problems somewhere where this notification comes too late but that's out of my hands as all the datasourcecontrol does is simply say "I'm changed!" and that's it.

If they're placed higher up the html, it might be they're evaluated first, and thus are known when the rest is rendered.

Frans Bouma | Lead developer LLBLGen Pro
Posts: 24
Joined: 19-Feb-2007
# Posted on: 12-Mar-2007 19:25:31   

I tried adding the datasourcecontrols to the top of the template and I got this error:


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: 


[No relevant source lines]


Source File: c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\df5b591a\d8d171eb\App_Web_nlmdovyj.0.cs Line: 0 

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() +1999298
   ASP.admin_city_aspx.__DataBinding__control10(Object sender, EventArgs e) in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\df5b591a\d8d171eb\App_Web_nlmdovyj.0.cs:0
   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() +77
   System.Web.UI.Control.PreRenderRecursiveInternal() +161
   System.Web.UI.Control.PreRenderRecursiveInternal() +161
   System.Web.UI.Control.PreRenderRecursiveInternal() +161
   System.Web.UI.Control.PreRenderRecursiveInternal() +161
   System.Web.UI.Control.PreRenderRecursiveInternal() +161
   System.Web.UI.Control.PreRenderRecursiveInternal() +161
   System.Web.UI.Control.PreRenderRecursiveInternal() +161
   System.Web.UI.Control.PreRenderRecursiveInternal() +161
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1360




Thanks for all your help on this matter simple_smile .

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 12-Mar-2007 20:33:11   

Where exactly do you put the DataSources? Does your HTML looks like the following?

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="City.aspx.cs" Inherits="Admin_City" Title="Untitled Page" %>
<%@ Register Assembly="SD.LLBLGen.Pro.ORMSupportClasses.NET20" Namespace="SD.LLBLGen.Pro.ORMSupportClasses"
    TagPrefix="llblgenpro" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <llblgenpro:LLBLGenProDataSource id="LLBLGenProDataSource1" runat="server" DataContainerType="EntityCollection" EntityCollectionTypeName="DAL.CollectionClasses.CityCollection, App_Code.sbnhhox3" >
        <selectparameters>
            <asp:QueryStringParameter Name="CityId" QueryStringField="cityID"></asp:QueryStringParameter>
        </selectparameters>
    </llblgenpro:LLBLGenProDataSource>
    <llblgenpro:LLBLGenProDataSource id="llblgenDS2" runat="server" DataContainerType="EntityCollection"
EntityCollectionTypeName="DAL.CollectionClasses.StateCollection, App_Code.i0dy4x_t">
    </llblgenpro:LLBLGenProDataSource>
    <llblgenpro:LLBLGenProDataSource id="llblgenDS3" runat="server" DataContainerType="EntityCollection"
EntityCollectionTypeName="DAL.CollectionClasses.CountyCollection, App_Code.i0dy4x_t">
          <selectparameters>
            <asp:ControlParameter PropertyName="SelectedValue" Name="StateId" ControlID="stateID"></asp:ControlParameter>
          </selectparameters>
     </llblgenpro:LLBLGenProDataSource>
<asp:FormView ID="fvCity" runat="server" DataKeyNames="CityId" DataSourceID="LLBLGenProDataSource1">
        <EditItemTemplate>          
            <table class="CanyonDigital">
                <tr class="RowStyle">
                    <td class="HeaderStyle">
                        City:
                    </td>
                    <td>
                        <asp:TextBox ID="City" runat="server" Text='<%# Bind("City") %>'>
                        </asp:TextBox>
                    </td>
                </tr>
                <tr class="RowStyle">
                    <td class="HeaderStyle">
                        State:
                    </td>
                    <td>
                        <asp:DropDownList ID="stateID" runat="server" DataSourceID="llblgenDS2" DataTextField="state" DataValueField="stateID" AutoPostBack="True" SelectedValue='<%# Bind("StateId") %>'>
                        </asp:DropDownList>
                    </td>
                </tr>
                <tr class="RowStyle">
                    <td class="HeaderStyle">
                        County:
                    </td>
                    <td>
                        <asp:DropDownList ID="countyID" runat="server" DataSourceID="llblgenDS3" DataTextField="county" DataValueField="countyID" SelectedValue='<%# Bind("CountyId") %>' EnableViewState="false">
                        </asp:DropDownList>
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:Button ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
                            Text="Update">
                        </asp:Button>
                    </td>
                </tr>
            </table> 
        </EditItemTemplate>
    </asp:FormView>
</asp:Content>

Posts: 24
Joined: 19-Feb-2007
# Posted on: 12-Mar-2007 23:33:07   

I tried it at the top of the page (like you posted) and the bottom and neither of them work. I get the "Could not find control 'stateID' in ControlParameter 'StateId'." error that I posted previously.

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 13-Mar-2007 08:24:06   

I think I got it simple_smile

In the dropDownList "stateId", the datavalue is called stateId But in the SelectParameter of the LLBLGenProDataSource you have typed it as StateId, and it's case sensetive.

Also in the dropDownList you Bind the SelectedValue to StateId. So if the entityField is StateId, you should change the DataValueField to be StateId too.


<llblgenpro:LLBLGenProDataSource id="llblgenDS3" runat="server" DataContainerType="EntityCollection"
EntityCollectionTypeName="DAL.CollectionClasses.CountyCollection, App_Code.i0dy4x_t">
         <selectparameters>
            <asp:ControlParameter PropertyName="SelectedValue" Name="StateId" ControlID="stateID"></asp:ControlParameter>
         </selectparameters>
</llblgenpro:LLBLGenProDataSource>

<asp:DropDownList ID="stateID" runat="server" DataSourceID="llblgenDS2" DataTextField="state" DataValueField="stateID" AutoPostBack="True" SelectedValue='<%# Bind("StateId") %>'>

Posts: 24
Joined: 19-Feb-2007
# Posted on: 13-Mar-2007 18:14:09   

Unfortunately that didn't work either. I get the same message as before:


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: 


[No relevant source lines]


Source File: c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\df5b591a\d8d171eb\App_Web_buhdqelb.16.cs    Line: 0 

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() +1999298
   ASP.admin_city_aspx.__DataBinding__control7(Object sender, EventArgs e) in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\df5b591a\d8d171eb\App_Web_buhdqelb.16.cs:0
   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() +77
   System.Web.UI.Control.PreRenderRecursiveInternal() +161
   System.Web.UI.Control.PreRenderRecursiveInternal() +161
   System.Web.UI.Control.PreRenderRecursiveInternal() +161
   System.Web.UI.Control.PreRenderRecursiveInternal() +161
   System.Web.UI.Control.PreRenderRecursiveInternal() +161
   System.Web.UI.Control.PreRenderRecursiveInternal() +161
   System.Web.UI.Control.PreRenderRecursiveInternal() +161
   System.Web.UI.Control.PreRenderRecursiveInternal() +161
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1360




Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 13-Mar-2007 22:51:28   

With some googling for that last error, I found the following post

Posts: 24
Joined: 19-Feb-2007
# Posted on: 14-Mar-2007 01:52:04   

I'm not sure I understand what his solution is. Where does he want to change the "=" to a "#"? Do you understand what he's trying to recommend? If so, I'd appreciate another person's viewpoint. Thanks for everything so far...simple_smile

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 14-Mar-2007 08:19:50   

change a “=” to a “#”

I think he ment the "#" in the <%# Bind("Anything") %>.

One solution I found was disable the view state of that page

Did you try this?

I ran out of ideas, I hope someone else can help you in this issue.

Posts: 24
Joined: 19-Feb-2007
# Posted on: 14-Mar-2007 19:36:43   

I tried to EnableViewState in the page and that did not work as well. Thanks for all your help up to this point. Hopefully someone else has run into this problem and found a solution.

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 15-Mar-2007 09:11:06   

Thanks for all your help up to this point.

Not at all.

Hopefully someone else has run into this problem and found a solution.

I hope so.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 17-Mar-2007 13:51:58   

Also keep in mind that you use lowercased names of the fields you refer to. That's NEVER going to work. ALL names have to be specified with the right casing. 'countryId' is not a valid name, it's 'CountryId'.

The error seems something with the ASP.NET stuff. Try running the page in debugging mode and see where the page breaks. You DID post 2 different errors, (the bind crap and the can't find field error).

Frans Bouma | Lead developer LLBLGen Pro