INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

FormView Cascading DropDownList Binding problemHelpful Member! 

Qik3Coder (Programmer) (OP)
18 Apr 12 19:21
Let me preface this with I didn't create this nightmare.

Page Setup:
There is a custom object data source which is used to "collect" all the bound field values, and place the values in SESSION, so that they can be put in an XML document on a downstream page.
There are separate Edit/Insert item templates, which are basically the same control.
There are SQL data sources within the templates to load drop downs.
I cannot change the architecture of the site as it is out of scope.
I have added a "empty" row to both drop downs for the initial page load.

Problem:
DropDown 1 works all the time with
SelectedValue='<%# Bind("sessionValue1") %>'

DropDown 2 works in the "Insert" mode with
SelectedItem='<%# Bind("sessionValue2") %>'

DropDown 2 throws a "ListItem Not Serializable" when I RETURN to the page and it's in EDIT mode, using SelectedItem

DropDown 2 throws a "Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control." when I use SelectedValue instead of SelectedItem on postback, but not on initial load.

Thanks in advance,
Lodlaiden

You've got questions and source code. We want both!

jbenson001 (Programmer)
18 Apr 12 20:03
The first thing I would do is take any binding code out of the markup.  This is classic ASP type of coding.  I am not sure why this would cause an error without more code posted.  Set the selecteditem or selectedvalue from the codebehind, in the proper event and see if that eliminates any or all of the errors.
jbenson001 (Programmer)
18 Apr 12 20:09
Also, what exactly is being stored in the session variables?  Post the exact code that puts it there.
Qik3Coder (Programmer) (OP)
18 Apr 12 20:11

CODE

 <asp:FormView ID="FormView2" runat="server" DataSourceID="GenericBindObjectDataSource1"
            DefaultMode="Insert" OnItemInserting="FormView2_ItemInserting" OnInit="ItemsPage_Init"
            OnItemUpdating="FormView2_ItemUpdating" OnDataBound="FormView2_DataBound">

...

   <InsertItemTemplate>
                <div id="body">
                    <font color="red">*</font>Service Carrier:
                    <asp:DropDownList ID="ddlCarrier" runat="server" SelectedValue='<%# Bind("deviceCarrier") %>'
                        DataSourceID="sdsGetCarriers" DataTextField="Carrier" DataValueField="Carrier"
                        AutoPostBack="true" />
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Carrier is required!"
                        Text="!" ValidationGroup="ValInsert" ControlToValidate="ddlCarrier" InitialValue="[Select Carrier]"></asp:RequiredFieldValidator>
                    <br />
                    <br />
                    <font color="red">*</font>Device Model:
                    <asp:DropDownList ID="ddlDevice" runat="server" SelectedValue='<%# Bind("deviceModel") %>'
                        DataSourceID="sdsGetDevices" DataTextField="DisplayText" DataValueField="SelectedValue"
                        AutoPostBack="true" AppendDataBoundItems="true" />
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="Specific Device Model is required!"
                        Text="!" ValidationGroup="ValInsert" ControlToValidate="ddlDevice" InitialValue="[Select Mobile Device]"></asp:RequiredFieldValidator>
                    <br />
                    <br />

...
  <asp:SqlDataSource ID="sdsGetCarriers" runat="server" SelectCommand="prcGetSupportedHardwareCarriers"
                    ConnectionString="<%$ ConnectionStrings:XYZ %>" SelectCommandType="StoredProcedure">
                    <SelectParameters>
                        <asp:QueryStringParameter Name="DisplayGroup" QueryStringField="DisplayGroup" Type="String" />
                    </SelectParameters>
                </asp:SqlDataSource>
                <asp:SqlDataSource ID="sdsGetDevices" runat="server" SelectCommand="prcGetSupportedHardware"
                    ConnectionString="<%$ ConnectionStrings:XYZ%>" SelectCommandType="StoredProcedure">
                    <SelectParameters>
                        <asp:ControlParameter ControlID="ddlCarrier" PropertyName="Text" Name="Carrier" Type="String" />
                        <asp:QueryStringParameter Name="DisplayGroup" QueryStringField="DisplayGroup" Type="String" />
                    </SelectParameters>
                </asp:SqlDataSource>

You've got questions and source code. We want both!

jbenson001 (Programmer)
18 Apr 12 20:15
I need to see the code that places any values into the session variables.
Qik3Coder (Programmer) (OP)
18 Apr 12 20:19
It took me (way longer than it should have) to trace how this thing works.

It stores a custom dictionary object in session with name value pairs. It uses the X in bind("X") to determine the key. the value is whatever property it's attached to.

These values are then stored in a XML doc.

You've got questions and source code. We want both!

Qik3Coder (Programmer) (OP)
18 Apr 12 20:22
That's where it get's smelly.


This is at the bottom of every page:

CODE

 <gbd:GenericBindObjectDataSource ID="GenericBindObjectDataSource1" runat="server"
        SelectMethod="GetById" TypeName="X.Y.ItemCollection" RemoveEmptyFields="False"
        UpdateMethod="Update" InsertMethod="Insert">
        <SelectParameters>
            <asp:SessionParameter Name="id" SessionField="ID" Type="Object" />
        </SelectParameters>
    </gbd:GenericBindObjectDataSource>

Pertinent Guts of ItemCollection

CODE

     
            [System.ComponentModel.DataObjectMethodAttribute( System.ComponentModel.DataObjectMethodType.Insert, true )]
            public void Insert( OrderedDictionary fields )
            {
                if( !this.ItemHasRequiredFields( fields ) )
                {
                    throw new ArgumentException( "X." );
                }
                

                // Add any columns that don't already exist to the DataTable.
                //
                    foreach( DictionaryEntry de in fields )
                    {
                        if( !OrderItems.Columns.Contains( de.Key.ToString() ) )
                        {
                            OrderItems.Columns.Add( de.Key.ToString() );
                        }
                    }


                // Build a new row.
                //
                    DataRow row = this.BuildDataRowFromOrderedDictionary( fields );
                    this.InsertInternal( row );       
            }


            private void InsertInternal( DataRow row )
            {
                OrderItems.Rows.Add( row );
            }

[/code]
 

You've got questions and source code. We want both!

Helpful Member!  jbenson001 (Programmer)
18 Apr 12 20:23
As your error states, ListItems are not serializable.  So you have to trace through and find out what is trying to be stored in session when this error occurs.    
Qik3Coder (Programmer) (OP)
19 Apr 12 17:53
Sorry it took this long to respond, production issue... (Who the heck puts a "/" in an AD Group Name!!!)

I had already traced it, but your comment prompted me to re-assess the code.

I added the following block after the foreach that iterates over the keys:

CODE

  //Save the Value of any ListItems that are stored
            int i = 0;
            while (i < fields.Count)
            {
                Object o = fields[i];
                if (o.GetType().FullName.ToString().ToLower().Contains("listitem"))
                    fields[i] = ((System.Web.UI.WebControls.ListItem)o).Value;
                i++;
            }

That was throwing an odd "Cannot serialized" list item on the page load, for the default item.

I changed the binding on the Edit Template to be SelectedValue instead of SelectedItem, which appears to have resolved my issue.
The insert template is still using SelectedItem.

Thanks for the help!
Lodlaiden

You've got questions and source code. We want both!

jbenson001 (Programmer)
20 Apr 12 9:47
Glad I could point you in the right direction.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close