I have a simple textbox and a simple dropdownlist like this:
<asp:TextBox ID="txtState" runat="server" Width="200px" AutoPostBack="true" ></asp:TextBox>
<asp:DropDownList ID="cboCities" runat="server" Width="200px" AutoPostBack="true" > </asp:DropDownList>
When the user enters a state in the textbox, I want to fill the dropdownlist with appropriate cities. I am using an Open Access Data Model.I have tried several different ways to bind the dropdownlist in the page’s load complete event when it detects that txtState.text <> “” and cboCities.items.count = 0
'Attempt 1
'No errors but no values filled either. If it did work I would want to replace the where clause with c.State = txtState.text
Using model As New MyDataModel.EntitiesModel
Dim Stations As List(Of City) = (From c In model.Cities Where c.State = "MA" _ And c.IsActive = 1).ToList
If Not Stations Is Nothing Then
cboCities.DataSource = Stations
cboCities.DataBind()
End If
End Using
'Attempt 2
''this one works but doesn't have the ability to filter by state. DBContext is defined on the DataAccesPage which this page inherits from
cboCities.DataSource = DbContext.Cities.ToList()
cboCities.DataTextField = "CityID"
cboCities.DataBind()
'Attempt 3
'THIS ONE WORKS TO FILL THE CBO BUT ANY CODE AFTER THIS THROWS ERRORS I really wanted this one to work because it calls a function in my ' 'BLL (FillCitiesList) which seems the most “Proper” way to go about it
Dim listStations As IQueryable(Of CanFillStation)
listStations = FillCitiesList ("MA”)
cboCities.DataSource = listStations
cboCities.DataBind()
Public Function FillCitiesList (ByVal stState As String) As IQueryable(Of City)
Using model As New MyDataModel.EntitiesModel
Dim query = From c In model.Cities Where c.State = strState
Select c
Return query
End Using
End Function
This is the error message that is thrown after attempt 3 code executes:
System.ObjectDisposedException was unhandled by user code Message=The ObjectScope has already been disposed and it's managed persistent objects can no longer be accessed. The ObjectScope should be disposed at the end of the life cycle of your business logic instance. This can also be done in the Dispose of your ASP page or MVC controller.Object name: 'OpenAccessRuntime.EnlistableObjectScope'. ObjectName=OpenAccessRuntime.EnlistableObjectScope Source=Telerik.OpenAccess.Runtime StackTrace: at OpenAccessRuntime.ObjectScope.CheckNotDisposed() at OpenAccessRuntime.ObjectScope.Telerik.OpenAccess.SPI.IExtendedObjectScope.get_ShouldLogExpressions() at Telerik.OpenAccess.Query.ExtentQueryImpl`1.Telerik.OpenAccess.Query.ExecutionSettings.get_ShouldLogExpressions() at Telerik.OpenAccess.Query.ExpressionCutter.CutAndExecute(Expression expression, ExecutionSettings settings, Expression whole) at Telerik.OpenAccess.Query.Piece`1.ExecuteMultiple() at Telerik.OpenAccess.Query.Piece`1.System.Collections.IEnumerable.GetEnumerator() at System.Web.UI.WebControls.ListControl.PerformDataBinding(IEnumerable dataSource) at System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e) at System.Web.UI.WebControls.ListControl.PerformSelect() at System.Web.UI.WebControls.BaseDataBoundControl.DataBind() at ELSATracking.EditRelations.Page_LoadComplete(Object sender, EventArgs e) in C:\_DEVELOPMENT\ELSATracking\ELSATracking\UserPages\Shop\EditRelations.aspx.vb:line 132 at System.Web.UI.Page.OnLoadComplete(EventArgs e) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) InnerException:
Obviously, I don't know what I'm doing! Can anyone help me fill the dropdownlist programatically after the user enters a state, using OpenAccess, and preferably using a business layer function?
Thanks
<asp:TextBox ID="txtState" runat="server" Width="200px" AutoPostBack="true" ></asp:TextBox>
<asp:DropDownList ID="cboCities" runat="server" Width="200px" AutoPostBack="true" > </asp:DropDownList>
When the user enters a state in the textbox, I want to fill the dropdownlist with appropriate cities. I am using an Open Access Data Model.I have tried several different ways to bind the dropdownlist in the page’s load complete event when it detects that txtState.text <> “” and cboCities.items.count = 0
'Attempt 1
'No errors but no values filled either. If it did work I would want to replace the where clause with c.State = txtState.text
Using model As New MyDataModel.EntitiesModel
Dim Stations As List(Of City) = (From c In model.Cities Where c.State = "MA" _ And c.IsActive = 1).ToList
If Not Stations Is Nothing Then
cboCities.DataSource = Stations
cboCities.DataBind()
End If
End Using
'Attempt 2
''this one works but doesn't have the ability to filter by state. DBContext is defined on the DataAccesPage which this page inherits from
cboCities.DataSource = DbContext.Cities.ToList()
cboCities.DataTextField = "CityID"
cboCities.DataBind()
'Attempt 3
'THIS ONE WORKS TO FILL THE CBO BUT ANY CODE AFTER THIS THROWS ERRORS I really wanted this one to work because it calls a function in my ' 'BLL (FillCitiesList) which seems the most “Proper” way to go about it
Dim listStations As IQueryable(Of CanFillStation)
listStations = FillCitiesList ("MA”)
cboCities.DataSource = listStations
cboCities.DataBind()
Public Function FillCitiesList (ByVal stState As String) As IQueryable(Of City)
Using model As New MyDataModel.EntitiesModel
Dim query = From c In model.Cities Where c.State = strState
Select c
Return query
End Using
End Function
This is the error message that is thrown after attempt 3 code executes:
System.ObjectDisposedException was unhandled by user code Message=The ObjectScope has already been disposed and it's managed persistent objects can no longer be accessed. The ObjectScope should be disposed at the end of the life cycle of your business logic instance. This can also be done in the Dispose of your ASP page or MVC controller.Object name: 'OpenAccessRuntime.EnlistableObjectScope'. ObjectName=OpenAccessRuntime.EnlistableObjectScope Source=Telerik.OpenAccess.Runtime StackTrace: at OpenAccessRuntime.ObjectScope.CheckNotDisposed() at OpenAccessRuntime.ObjectScope.Telerik.OpenAccess.SPI.IExtendedObjectScope.get_ShouldLogExpressions() at Telerik.OpenAccess.Query.ExtentQueryImpl`1.Telerik.OpenAccess.Query.ExecutionSettings.get_ShouldLogExpressions() at Telerik.OpenAccess.Query.ExpressionCutter.CutAndExecute(Expression expression, ExecutionSettings settings, Expression whole) at Telerik.OpenAccess.Query.Piece`1.ExecuteMultiple() at Telerik.OpenAccess.Query.Piece`1.System.Collections.IEnumerable.GetEnumerator() at System.Web.UI.WebControls.ListControl.PerformDataBinding(IEnumerable dataSource) at System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e) at System.Web.UI.WebControls.ListControl.PerformSelect() at System.Web.UI.WebControls.BaseDataBoundControl.DataBind() at ELSATracking.EditRelations.Page_LoadComplete(Object sender, EventArgs e) in C:\_DEVELOPMENT\ELSATracking\ELSATracking\UserPages\Shop\EditRelations.aspx.vb:line 132 at System.Web.UI.Page.OnLoadComplete(EventArgs e) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) InnerException:
Obviously, I don't know what I'm doing! Can anyone help me fill the dropdownlist programatically after the user enters a state, using OpenAccess, and preferably using a business layer function?
Thanks