Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 11th, 2007, 12:36 PM
Registered User
 
Join Date: Apr 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default FormView/ObjectDataSource/DropDownList Problem

Using Imar Spaanjars' model for layered web applications, I have built a small one of my own. Inside a FormView I have a DropDownList containing states. I am trying to set the SelectedValue of the DropDownList to the value that is in an object named Contact.cs. I have tried these two techniques and neither one works:

Technique #1:
The DropDownList displays the correct state the first time but the PREVIOUS state on subsequent selections in the parent GridView.
Code:
<asp:DropDownList ID="ddlAddState" runat="server" 
                     SelectedValue='<%# Bind("state") %>'
                     AppendDataBoundItems="True"
                     DataSourceID="odsStates3" DataTextField="abbr" 
                     DataValueField="abbr" TabIndex="8">
                        <asp:ListItem>Select...</asp:ListItem>
                    </asp:DropDownList>
                    <asp:ObjectDataSource ID="odsStates3" 
                     runat="server" SelectMethod="SelectStates"
                     TypeName="GeneralDB">
                    </asp:ObjectDataSource>
Technique #2:
The Debug line displays the correct state but the DropDownList displays the PREVIOUS state.
Code:
protected void fvContact_DataBound(object sender, EventArgs e)
    {
     if (fvContact.CurrentMode == FormViewMode.Edit)
        {
            Contact myContact = null;
            IEnumerable ie = odsFvContacts.Select();
            if (ie != null)
            {
                IEnumerator num = ie.GetEnumerator();
                if (num.MoveNext())
                {
                    myContact = (Contact)num.Current;   //Gets the class
                }
            }
            Debug.WriteLine("fvContact_DataBound: " + myContact.State);
            DropDownList ddl = (DropDownList)fvContact.FindControl("ddlState");
            ddl.ClearSelection();
            ddl.SelectedIndex 
                = ddl.Items.IndexOf(ddl.Items.FindByText(myContact.State));
        }
}
I would be happy to post more code if that would be helpful to the community.
 
Old April 12th, 2007, 11:58 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Could this be a state issue? Maybe you need to rebind your lists in the data bound events of the parent controls?

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 
Old April 13th, 2007, 01:10 PM
Registered User
 
Join Date: Apr 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm not sure what's going on. This morning, after my nightly reboot, it is working fine with the normal declarative binding: SelectedValue='<%# Bind("state") %>'
 
Old April 14th, 2007, 02:50 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Great. Glad it's working now and that it wasn't "a problem that is specific to the kinds of objects [I am] using in [my] articles" after all....

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.





Similar Threads
Thread Thread Starter Forum Replies Last Post
FormView - access DropDownList controls kgaughan ASP.NET 2.0 Basics 0 July 29th, 2008 01:40 PM
Problem with ObjectDataSource miguel.ossa ASP.NET 2.0 Professional 1 February 9th, 2008 08:37 AM
DropDownList Inside FormView Problem frogosteve ASP.NET 2.0 Basics 0 April 12th, 2007 10:30 AM
Problem with ObjectDataSource... veeruu ASP.NET 2.0 Professional 0 March 2nd, 2007 07:45 AM
Formview with ObjectDataSource rturner003 ASP.NET 2.0 Professional 3 November 1st, 2006 06:17 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.