Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1148
  • Last Modified:

Using GridView's SelectParameter where Type="Object" causes FormView to not work

I have a formview that isn't updating when I use a controlparameter tied to a grid's selected value.  This only happens when the grid uses a parameter that is of type object.  I thought that it might be our project, so I created a brand new solution with only a gridview, formview, and two objectdatasources and it still doesn't work.

This is the code that doesn't work:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            DataSourceID="ObjectDataSource1" DataKeyNames="ID">
            <Columns>
                <asp:CommandField ShowSelectButton="True" />
                <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                <asp:BoundField DataField="Address" HeaderText="Address" 
                    SortExpression="Address" />
                <asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" />
            </Columns>
        </asp:GridView>
        <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
            SelectMethod="GetAllUsingObject" TypeName="TestingAppContext.Provider">
            <SelectParameters>
                <asp:SessionParameter Name="myObj" SessionField="SessionObj" Type="Object" />
            </SelectParameters>
        </asp:ObjectDataSource>

Open in new window


Formview's code tied to the Gridview above:
        <asp:ObjectDataSource ID="ObjectDataSource2" runat="server" 
            SelectMethod="GetByKeyUsingObject" TypeName="TestingAppContext.Provider">
            <SelectParameters>
                <asp:ControlParameter ControlID="GridView1" Name="key" 
                    PropertyName="SelectedValue" Type="Int32" />
            </SelectParameters>
        </asp:ObjectDataSource>

Open in new window


This is the code that does work:
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" 
            DataSourceID="ObjectDataSource3" DataKeyNames="ID">
            <Columns>
                <asp:CommandField ShowSelectButton="True" />
                <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                <asp:BoundField DataField="Address" HeaderText="Address" 
                    SortExpression="Address" />
                <asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" />
            </Columns>
        </asp:GridView>
        <asp:ObjectDataSource ID="ObjectDataSource3" runat="server" 
            SelectMethod="GetAllUsingInteger" TypeName="TestingAppContext.Provider">
            <SelectParameters>
                <asp:SessionParameter Name="value" SessionField="SessionInt" Type="Int32" />
            </SelectParameters>
        </asp:ObjectDataSource>

Open in new window


Formview's code tied to the Gridview above:
        <asp:ObjectDataSource ID="ObjectDataSource4" runat="server" 
            SelectMethod="GetByKeyUsingInteger" TypeName="TestingAppContext.Provider">
            <SelectParameters>
                <asp:ControlParameter ControlID="GridView2" Name="key" 
                    PropertyName="SelectedValue" Type="Int32" />
            </SelectParameters>
        </asp:ObjectDataSource>

Open in new window


I have my select parameters for the objdatasource1 set to an object that's stored in session.  The grid displays correctly and also successfully passes in "myObj." (When I debugged, I was able to view the object correctly).  When I select a row in the gridview, nothing happens with the formview.

What I've done so far:
Another weird thing that happens is if I debug the code and place the formview or gridview into the watch window, then everything works correctly.
I also thought it might be session state and so I created a custom parameter that returned an object and had the same outcome..  (When I returned a string or int instead, the custom parameter would work correctly)
So I was wondering if anybody can shed some light onto why my Formview doesn't work when I have a selected paramter of type object in my Gridview.  Also what would be a way to fix it or a workaround?

-Thanks
0
ToolTimeGang
Asked:
ToolTimeGang
  • 8
  • 8
1 Solution
 
CmdoProg2Commented:
What is the type of the ID column being returned by ObjectDataSource1 and ObjectDataSource3?  It may be the implicit converson to integer.
0
 
ToolTimeGangAuthor Commented:
Sorry for the delay.  Busy week!  ID is of type Integer.  so I'm not quite sure I understand what you mean.  Should I add a conversion somewhere?  If so, where?  Can you provide a sample of what you mean?
0
 
CmdoProg2Commented:
My thought was in your Objectdatasource with GetAllUsingObject that the return ID may be of type object.  Exactly how is the formview not working?  Are you getting an error or doesn't display expected results?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
ToolTimeGangAuthor Commented:
No error.  Its just that the formview does not display the values for the row that was selected.
Recap:
The one that doesn't work is using this for the gridview's ods SelectParameter:
<asp:SessionParameter Name="myObj" SessionField="SessionObj" Type="Object" />

The one that does work is using this:
<asp:SessionParameter Name="value" SessionField="SessionInt" Type="Int32" />

Here is a picture of the example at run time.
In the 1st one, if you click on any of the Select links, the formview right below the gridview remains the same values.
In the 2nd one, if you click on any of the Select links, the formview correctly displays the row values in the formview. (for the 2nd, I had just clicked the Select link on the 2nd row...as you can see, the formview is correctly showing the values)
Does that help CmdoProg2?
   runtime display
0
 
CmdoProg2Commented:
I am suspecting a difference between ObjectDataSource2's SelectMethod="GetByKeyUsingObject" and ObjectDataSource4's  SelectMethod="GetByKeyUsingInteger".  Since your datakeyfield, ID, in the Gridviews are integer types, you should use the same routine.  Try changing the ObjectDataSource2's SelectMethod to "GetByKeyUsingInteger"..
0
 
ToolTimeGangAuthor Commented:
Didn't work.  Same results.
0
 
CmdoProg2Commented:
Are you using 2.0,3.5, or 4.0 framework? VS 2008 or VS2010?   It will be Monday or Tuesday before I can setup a full test environment to duplicate this issue.
0
 
ToolTimeGangAuthor Commented:
4.00 with VS 2010.
Would you like me to include the source for the sample here?  (Including the busines/data tiers)
Thank you for helping...Monday is just fine!
0
 
CmdoProg2Commented:
That would be great.
0
 
ToolTimeGangAuthor Commented:
Source for index.aspx
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Index.aspx.vb" Inherits="TestingAppContext.Index" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <br />
        Example that does NOT work:<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            DataSourceID="ObjectDataSource1" DataKeyNames="ID">
            <Columns>
                <asp:CommandField ShowSelectButton="True" />
                <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                <asp:BoundField DataField="Address" HeaderText="Address" 
                    SortExpression="Address" />
                <asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" />
            </Columns>
        </asp:GridView>
        <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
            SelectMethod="GetAllUsingObject" TypeName="TestingAppContext.Provider">
            <SelectParameters>
                <asp:SessionParameter Name="myObj" SessionField="SessionObj" Type="Object" />
            </SelectParameters>
        </asp:ObjectDataSource>
        <asp:FormView ID="FormView1" runat="server" DataSourceID="ObjectDataSource2" DataKeyNames="ID">
            <EditItemTemplate>
                Name:
                <asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
                <br />
                Address:
                <asp:TextBox ID="AddressTextBox" runat="server" Text='<%# Bind("Address") %>' />
                <br />
                ID:
                <asp:TextBox ID="IDTextBox" runat="server" Text='<%# Bind("ID") %>' />
                <br />
                <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" 
                    CommandName="Update" Text="Update" />
                &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" 
                    CausesValidation="False" CommandName="Cancel" Text="Cancel" />
            </EditItemTemplate>
            <InsertItemTemplate>
                Name:
                <asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
                <br />
                Address:
                <asp:TextBox ID="AddressTextBox" runat="server" Text='<%# Bind("Address") %>' />
                <br />
                ID:
                <asp:TextBox ID="IDTextBox" runat="server" Text='<%# Bind("ID") %>' />
                <br />
                <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" 
                    CommandName="Insert" Text="Insert" />
                &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" 
                    CausesValidation="False" CommandName="Cancel" Text="Cancel" />
            </InsertItemTemplate>
            <ItemTemplate>
                Name:
                <asp:Label ID="NameLabel" runat="server" Text='<%# Bind("Name") %>' />
                <br />
                Address:
                <asp:Label ID="AddressLabel" runat="server" Text='<%# Bind("Address") %>' />
                <br />
                ID:
                <asp:Label ID="IDLabel" runat="server" Text='<%# Bind("ID") %>' />
                <br />

            </ItemTemplate>
        </asp:FormView>
    
        <asp:ObjectDataSource ID="ObjectDataSource2" runat="server" 
            SelectMethod="GetByKeyUsingInteger" TypeName="TestingAppContext.Provider">
            <SelectParameters>
                <asp:ControlParameter ControlID="GridView1" Name="key" 
                    PropertyName="SelectedValue" Type="Int32" />
            </SelectParameters>
        </asp:ObjectDataSource>
    
    </div>

    <br />
    <br />
    Example that DOES work:<br />

        <div>
    
        <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" 
            DataSourceID="ObjectDataSource3" DataKeyNames="ID">
            <Columns>
                <asp:CommandField ShowSelectButton="True" />
                <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                <asp:BoundField DataField="Address" HeaderText="Address" 
                    SortExpression="Address" />
                <asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" />
            </Columns>
        </asp:GridView>
        <asp:ObjectDataSource ID="ObjectDataSource3" runat="server" 
            SelectMethod="GetAllUsingInteger" TypeName="TestingAppContext.Provider">
            <SelectParameters>
                <asp:SessionParameter Name="value" SessionField="SessionInt" Type="Int32" />
            </SelectParameters>
        </asp:ObjectDataSource>
        <asp:FormView ID="FormView2" runat="server" DataSourceID="ObjectDataSource4" DataKeyNames="ID">
            <EditItemTemplate>
                Name:
                <asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
                <br />
                Address:
                <asp:TextBox ID="AddressTextBox" runat="server" Text='<%# Bind("Address") %>' />
                <br />
                ID:
                <asp:TextBox ID="IDTextBox" runat="server" Text='<%# Bind("ID") %>' />
                <br />
                <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" 
                    CommandName="Update" Text="Update" />
                &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" 
                    CausesValidation="False" CommandName="Cancel" Text="Cancel" />
            </EditItemTemplate>
            <InsertItemTemplate>
                Name:
                <asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
                <br />
                Address:
                <asp:TextBox ID="AddressTextBox" runat="server" Text='<%# Bind("Address") %>' />
                <br />
                ID:
                <asp:TextBox ID="IDTextBox" runat="server" Text='<%# Bind("ID") %>' />
                <br />
                <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" 
                    CommandName="Insert" Text="Insert" />
                &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" 
                    CausesValidation="False" CommandName="Cancel" Text="Cancel" />
            </InsertItemTemplate>
            <ItemTemplate>
                Name:
                <asp:Label ID="NameLabel" runat="server" Text='<%# Bind("Name") %>' />
                <br />
                Address:
                <asp:Label ID="AddressLabel" runat="server" Text='<%# Bind("Address") %>' />
                <br />
                ID:
                <asp:Label ID="IDLabel" runat="server" Text='<%# Bind("ID") %>' />
                <br />

            </ItemTemplate>
        </asp:FormView>
    
        <asp:ObjectDataSource ID="ObjectDataSource4" runat="server" 
            SelectMethod="GetByKeyUsingInteger" TypeName="TestingAppContext.Provider">
            <SelectParameters>
                <asp:ControlParameter ControlID="GridView2" Name="key" 
                    PropertyName="SelectedValue" Type="Int32" />
            </SelectParameters>
        </asp:ObjectDataSource>
    
    </div>
    </form>
</body>
</html>

Open in new window


Provider.vb
Public Class Provider

    Public Function GetAllUsingObject(ByVal myObj As ValueObject) As IList(Of CustomObject)

        Dim myList As New List(Of CustomObject)

        Dim c1 As New CustomObject With {
        .Name = "N1",
        .Address = "A1",
        .ID = myObj.Value
        }

        Dim c2 As New CustomObject With {
        .Name = "N2",
        .Address = "A2",
        .ID = myObj.Value + 1
        }
        Dim c3 As New CustomObject With {
        .Name = "N3",
        .Address = "A3",
        .ID = myObj.Value + 2
        }

        myList.Add(c1)
        myList.Add(c2)
        myList.Add(c3)

        Return myList

    End Function

    Public Function GetAllUsingInteger(ByVal value As Integer) As IList(Of CustomObject)

        Dim myList As New List(Of CustomObject)

        Dim c1 As New CustomObject With {
        .Name = "N1",
        .Address = "A1",
        .ID = value
        }

        Dim c2 As New CustomObject With {
        .Name = "N2",
        .Address = "A2",
        .ID = value + 1
        }
        Dim c3 As New CustomObject With {
        .Name = "N3",
        .Address = "A3",
        .ID = value + 2
        }

        myList.Add(c1)
        myList.Add(c2)
        myList.Add(c3)

        Return myList

    End Function

    Public Function GetByKeyUsingObject(ByVal key As Integer) As CustomObject

        Dim temp = GetAllUsingObject(HttpContext.Current.Session("SessionObj"))

        Return temp(key)

    End Function

    Public Function GetByKeyUsingInteger(ByVal key As Integer) As CustomObject

        Dim temp = GetAllUsingInteger(HttpContext.Current.Session("SessionInt"))

        Return temp(key)

    End Function

End Class

Open in new window

codebehind for index.aspx:
Public Class Index
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Session("SessionObj") = New ValueObject(0)
        Session("SessionInt") = 0
    End Sub

 End Class

Open in new window


CustomObject.vb
Public Class CustomObject

    Private _name As String
    Private _address As String
    Private _id As Integer

    Public Property Name As String
        Get
            Return _name
        End Get
        Set(ByVal value As String)
            _name = value
        End Set
    End Property
    Public Property Address As String
        Get
            Return _address
        End Get
        Set(ByVal value As String)
            _address = value
        End Set
    End Property
    Public Property ID As Integer
        Get
            Return _id
        End Get
        Set(ByVal value As Integer)
            _id = value
        End Set
    End Property

End Class

Open in new window


ValueObject.vb
<Serializable()>
Public Class ValueObject

    Private _value As Integer

    Public Sub New(ByRef value As Integer)
        _value = value
    End Sub

    Public Property Value As Integer
        Get
            Return _value
        End Get
        Set(ByVal value As Integer)
            _value = value
        End Set
    End Property

End Class

Open in new window

0
 
CmdoProg2Commented:
Your object is not a scalar object, but a custom class structure.  This is causing gridview1 to be reloaded every postback.  It loses the selectedindex (and value) after the gridview is rebounded (-1 index).   The objectdatasource2 of the formview1 is called since the value (Nothing) has not been changed.  References to the selectedvalue by other events retrieves the value before it is overwritten.  This includes references in the immediate window.  Adding a reference before as below

Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
    Dim SltValue As Integer
    SltValue = GridView1.SelectedValue
  End Sub

Open in new window


  Also, I changed the session to an object value and modified the session object without the above event.  
      Dim obj As Object = 0
      Session("SessionObj") = obj

Public Function GetAllUsingTueObject(ByVal myObj As Object) As IList(Of CustomObject)
      Dim myValueObject As New ValueObject(myObj)

      Dim myList As New List(Of CustomObject)

      Dim c1 As New CustomObject With {
      .Name = "N1",
      .Address = "A1",
      .ID = myValueObject.Value
      }

      Dim c2 As New CustomObject With {
      .Name = "N2",
      .Address = "A2",
      .ID = myValueObject.Value + 1
      }
      Dim c3 As New CustomObject With {
      .Name = "N3",
      .Address = "A3",
      .ID = myValueObject.Value + 2
      }

      myList.Add(c1)
      myList.Add(c2)
      myList.Add(c3)

      Return myList

    End Function

Open in new window

0
 
ToolTimeGangAuthor Commented:
I changed the Provider to include GetAllUsingTueObject.
I changed the ObjectdataSource1 to call GetAllUsingTueObject instead of GetAllUsingTuesObject.
I changed the creation of SessionObj as defined above.
I did not add an event for GridView1_SelectedIndexChanged.

Now I am getting: ObjectDataSource 'ObjectDataSource1' could not find a non-generic method 'GetAllUsingTuesObject' that has parameters: myObj
0
 
CmdoProg2Commented:
You may want to check the ObjectDataSource1.  I added the selected row background is set to silver

index.aspx
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <br />
        Example that does NOT work:<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            DataSourceID="ObjectDataSource1" DataKeyNames="ID">
            <Columns>
                <asp:CommandField ShowSelectButton="True" />
                <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                <asp:BoundField DataField="Address" HeaderText="Address" 
                    SortExpression="Address" />
                <asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" />
            </Columns>
            <SelectedRowStyle BackColor="Silver" />
        </asp:GridView>
        <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
            SelectMethod="GetAllUsingTueObject" TypeName="TestingAppContext.Provider">
            <SelectParameters>
                <asp:SessionParameter Name="myObj" SessionField="SessionObj" Type="Object" />
            </SelectParameters>
        </asp:ObjectDataSource>
        <asp:FormView ID="FormView1" runat="server" DataSourceID = "ObjectDataSource2" DataKeyNames="ID">
            <EditItemTemplate>
                Name:
                <asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
                <br />
                Address:
                <asp:TextBox ID="AddressTextBox" runat="server" Text='<%# Bind("Address") %>' />
                <br />
                ID:
                <asp:TextBox ID="IDTextBox" runat="server" Text='<%# Bind("ID") %>' />
                <br />
                <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" 
                    CommandName="Update" Text="Update" />
                &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" 
                    CausesValidation="False" CommandName="Cancel" Text="Cancel" />
            </EditItemTemplate>
            <InsertItemTemplate>
                Name:
                <asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
                <br />
                Address:
                <asp:TextBox ID="AddressTextBox" runat="server" Text='<%# Bind("Address") %>' />
                <br />
                ID:
                <asp:TextBox ID="IDTextBox" runat="server" Text='<%# Bind("ID") %>' />
                <br />
                <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" 
                    CommandName="Insert" Text="Insert" />
                &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" 
                    CausesValidation="False" CommandName="Cancel" Text="Cancel" />
            </InsertItemTemplate>
            <ItemTemplate>
                Name:
                <asp:Label ID="NameLabel" runat="server" Text='<%# Bind("Name") %>' />
                <br />
                Address:
                <asp:Label ID="AddressLabel" runat="server" Text='<%# Bind("Address") %>' />
                <br />
                ID:
                <asp:Label ID="IDLabel" runat="server" Text='<%# Bind("ID") %>' />
                <br />

            </ItemTemplate>
        </asp:FormView>
    
        <asp:ObjectDataSource ID="ObjectDataSource2" runat="server" 
            SelectMethod="GetByKeyUsingInteger" TypeName="TestingAppContext.Provider">
            <SelectParameters>
                <asp:ControlParameter ControlID="GridView1" Name="key" 
                    PropertyName="SelectedValue" Type="Int32" />
            </SelectParameters>
        </asp:ObjectDataSource>
    
    </div>

    <br />
    <br />
    Example that DOES work:<br />

        <div>
    
        <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" 
            DataSourceID="ObjectDataSource3" DataKeyNames="ID">
            <Columns>
                <asp:CommandField ShowSelectButton="True" />
                <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                <asp:BoundField DataField="Address" HeaderText="Address" 
                    SortExpression="Address" />
                <asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" />
            </Columns>
             <SelectedRowStyle BackColor="Silver" />
       </asp:GridView>
        <asp:ObjectDataSource ID="ObjectDataSource3" runat="server" 
            SelectMethod="GetAllUsingInteger" TypeName="TestingAppContext.Provider">
            <SelectParameters>
                <asp:SessionParameter Name="value" SessionField="SessionInt" Type="Int32" />
            </SelectParameters>
        </asp:ObjectDataSource>
        <asp:FormView ID="FormView2" runat="server" DataSourceID = "ObjectDataSource4" DataKeyNames="ID">
            <EditItemTemplate>
                Name:
                <asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
                <br />
                Address:
                <asp:TextBox ID="AddressTextBox" runat="server" Text='<%# Bind("Address") %>' />
                <br />
                ID:
                <asp:TextBox ID="IDTextBox" runat="server" Text='<%# Bind("ID") %>' />
                <br />
                <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" 
                    CommandName="Update" Text="Update" />
                &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" 
                    CausesValidation="False" CommandName="Cancel" Text="Cancel" />
            </EditItemTemplate>
            <InsertItemTemplate>
                Name:
                <asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
                <br />
                Address:
                <asp:TextBox ID="AddressTextBox" runat="server" Text='<%# Bind("Address") %>' />
                <br />
                ID:
                <asp:TextBox ID="IDTextBox" runat="server" Text='<%# Bind("ID") %>' />
                <br />
                <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" 
                    CommandName="Insert" Text="Insert" />
                &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" 
                    CausesValidation="False" CommandName="Cancel" Text="Cancel" />
            </InsertItemTemplate>
            <ItemTemplate>
                Name:
                <asp:Label ID="NameLabel" runat="server" Text='<%# Bind("Name") %>' />
                <br />
                Address:
                <asp:Label ID="AddressLabel" runat="server" Text='<%# Bind("Address") %>' />
                <br />
                ID:
                <asp:Label ID="IDLabel" runat="server" Text='<%# Bind("ID") %>' />
                <br />

            </ItemTemplate>
        </asp:FormView>
    
        <asp:ObjectDataSource ID="ObjectDataSource4" runat="server" 
            SelectMethod="GetByKeyUsingInteger" TypeName="TestingAppContext.Provider">
            <SelectParameters>
                <asp:ControlParameter ControlID="GridView2" Name="key" 
                    PropertyName="SelectedValue" Type="Int32" />
            </SelectParameters>
        </asp:ObjectDataSource>
    
    </div>
    </form>
</body>
</html>

Open in new window

 

index.aspx.vb

Partial Class Index
    Inherits System.Web.UI.Page

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim obj As Object = 0
    Session("SessionObj") = obj
    ''Session("SessionObj") = New ValueObject(0)
    Session("SessionInt") = 0

  End Sub

End Class

Open in new window

0
 
ToolTimeGangAuthor Commented:
thank you.  It is working now. This is the part I was missing:
        <asp:ObjectDataSource ID="ObjectDataSource2" runat="server"
            SelectMethod="GetByKeyUsingInteger" TypeName="TestingAppContext.Provider">

so the moral of the story is to use object instead of a custom class like ValueObject, right? by changing it to object makes it scalar?
0
 
CmdoProg2Commented:
Yes.  All types derive from object.  Storing a scalar value as object or integer retains the scalar type.
0
 
ToolTimeGangAuthor Commented:
Great!  Thank you.  I need to research one more thing on this to make sure it has "sunk in"...then I will mark this as complete.  Your time and effort are much appreciated!  
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 8
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now