Problem Setting Values in ASP.NET App

Problem Setting Values in ASP.NET App

Old forum URL:

eslater posted on Tuesday, December 07, 2010

I have an ASP.NET app with code similar to the ProjectTracker sample.  Here is a snippet I have:

Private Function GetEmployee() As Employee
        Dim businessObject As Object = Session("currentObject")
        If businessObject Is Nothing OrElse _
            Not TypeOf businessObject Is Employee Then
                Dim et As String = Request.QueryString("EmployeeID")
                If Not String.IsNullOrEmpty(et) Then
                    businessObject = Employee.GetByEmployeeID(et)
                    businessObject = Employee.NewEmployee
                    businessObject.EmployeeType = 1
                End If
                Session("currentObject") = businessObject
            Catch ex As System.Security.SecurityException
            End Try
        End If
        Return CType(businessObject, Employee)
    End Function

On the form I have 2 CslaDatasource objects.  One for the Employee and one to populate a combobox with EmployeeTypes.

The problem I am having is that I want to set the EmployeeType to 1 but it is not getting preselected in the combobox.  The form uses a FormView for binding and it binds fine in Edit mode but in insert mode the line where I set the EmployeeType to 1 does nothing.

Anybody have any ideas?

eslater replied on Tuesday, December 07, 2010

Well I solved the problem.  It had to do with the FormView being in insert mode.  In this case you need to set the values of the controls themselves to the default values in the object.

Copyright (c) Marimer LLC