Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 11th, 2007, 12:36 PM
Registered User
 
Join Date: Apr 2007
Location: Brentwood, TN, USA.
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.
  #2 (permalink)  
Old April 12th, 2007, 11:58 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 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.
  #3 (permalink)  
Old April 13th, 2007, 01:10 PM
Registered User
 
Join Date: Apr 2007
Location: Brentwood, TN, USA.
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") %>'
  #4 (permalink)  
Old April 14th, 2007, 02:50 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 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.
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 05:54 AM.


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