Solved

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

Posted on 2011-02-16
18
1,123 Views
Last Modified: 2012-05-11
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
Comment
Question by:ToolTimeGang
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 8
18 Comments
 
LVL 12

Expert Comment

by:CmdoProg2
ID: 34926828
What is the type of the ID column being returned by ObjectDataSource1 and ObjectDataSource3?  It may be the implicit converson to integer.
0
 

Author Comment

by:ToolTimeGang
ID: 34974026
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
 
LVL 12

Expert Comment

by:CmdoProg2
ID: 34980365
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:ToolTimeGang
ID: 34980638
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
 
LVL 12

Expert Comment

by:CmdoProg2
ID: 34980802
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
 

Author Comment

by:ToolTimeGang
ID: 34981218
Didn't work.  Same results.
0
 
LVL 12

Expert Comment

by:CmdoProg2
ID: 34981280
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
 

Author Comment

by:ToolTimeGang
ID: 34981416
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
 
LVL 12

Expert Comment

by:CmdoProg2
ID: 34981448
That would be great.
0
 

Author Comment

by:ToolTimeGang
ID: 34981515
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
 
LVL 12

Accepted Solution

by:
CmdoProg2 earned 500 total points
ID: 34997340
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
 

Author Comment

by:ToolTimeGang
ID: 35009501
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
 
LVL 12

Expert Comment

by:CmdoProg2
ID: 35010482
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
 

Author Comment

by:ToolTimeGang
ID: 35010763
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
 
LVL 12

Expert Comment

by:CmdoProg2
ID: 35011607
Yes.  All types derive from object.  Storing a scalar value as object or integer retains the scalar type.
0
 

Author Comment

by:ToolTimeGang
ID: 35011644
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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
asp.net web app 3 57
WPF and Powershell button hover change text 5 59
Can Selenium do Load Testing? 2 58
async questions 5 48
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question