473,756 Members | 2,721 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re-Binding A DropDownList Within A DetailsView

Hello. I'm having a bit of difficulty with some DropDownList controls
within templates in a DetailsView on my web form. Basically, I have a
form where a user is building a "location profile" with a handful of
fields. Two of the controls are a DropDownList of countries and a
DropDownList of states (populated from a provider that is known to be
working elsewhere in the website).

The idea is simple... If a user selects a different country than what
is currently selected, that control auto-posts and repopulates the
states with the correct list for that country. This works fine on a
form that's manually created, but is not working yet in a
DetailsView. Here is the code for these two rows and their templates
(sorry for any wrapping):
<asp:TemplateFi eld HeaderText="Cou ntry" SortExpression= "Country">
<ItemTemplate >
<asp:Label ID="lblCountry " runat="server" Text='<%#
Country.GetCoun tryByID(Convert .ToInt32(Eval(" CountryID"))).N ame %>'></
asp:Label>
</ItemTemplate>
<EditItemTempla te>
<asp:ObjectData Source ID="objCountrie s" runat="server"
TypeName="Count ry" SelectMethod="G etCountries" />
<asp:DropDownLi st ID="ddlCountry " runat="server" Width="99%"
SelectedValue=' <%# Bind("CountryID ") %>' DataSourceID="o bjCountries"
DataTextField=" Name" DataValueField= "ID" AutoPostBack="t rue" />
</EditItemTemplat e>
</asp:TemplateFie ld>
<asp:TemplateFi eld HeaderText="Sta te" SortExpression= "State">
<ItemTemplate >
<asp:Label ID="lblState" runat="server" Text='<%#
State.GetStateB yID(Convert.ToI nt32(Eval("Stat eID"))).Name %>'></
asp:Label>
</ItemTemplate>
<EditItemTempla te>
<asp:ObjectData Source ID="objStates" runat="server"
TypeName="State " SelectMethod="G etStates">
<SelectParamete rs>
<asp:ControlPar ameter ControlID="ddlC ountry"
PropertyName="S electedValue" Name="countryID " Type="Int32"
DefaultValue="2 25" />
</SelectParameter s>
</asp:ObjectDataS ource>
<asp:DropDownLi st ID="ddlState" runat="server" Width="99%"
SelectedValue=' <%# Bind("StateID") %>' DataSourceID="o bjStates"
DataTextField=" Name" DataValueField= "ID" />
</EditItemTemplat e>
</asp:TemplateFie ld>
This works fine when the page initially loads. The list of countries
is sorted alphabetically, so Afganistan is first. And the list of
states gets populated with the correct provinces based on the data
source. (I'll worry about conveniently defaulting to the US for the
majority of users later.) However, when I select a different country,
the following exception is thrown:
"Databindin g methods such as Eval(), XPath(), and Bind() can only be
used in the context of a databound control."
So far my testing has only involved using the DetailsView to insert a
record, so I'm only using the EditItemTempate s as of yet. Can anyone
offer any advice on why this might be happening?
Regards,
David

Mar 23 '07 #1
0 1522

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4323
by: Nel | last post by:
I have a question related to the "security" issues posed by Globals ON. It is good programming technique IMO to initialise variables, even if it's just $foo = 0; $bar = ""; Surely it would be better to promote better programming than rely on PHP to compensate for lazy programming?
4
6429
by: Craig Bailey | last post by:
Anyone recommend a good script editor for Mac OS X? Just finished a 4-day PHP class in front of a Windows machine, and liked the editor we used. Don't recall the name, but it gave line numbers as well as some color coding, etc. Having trouble finding the same in an editor that'll run on OS X. -- Floydian Slip(tm) - "Broadcasting from the dark side of the moon"
1
4101
by: Chris | last post by:
Sorry to post so much code all at once but I'm banging my head against the wall trying to get this to work! Does anyone have any idea where I'm going wrong? Thanks in advance and sorry again for adding so much code... <TABLE border="1" bordercolor="#000000" cellspacing="0"> <TR>
11
4010
by: James | last post by:
My form and results are on one page. If I use : if ($Company) { $query = "Select Company, Contact From tblworking Where ID = $Company Order By Company ASC"; }
4
18534
by: Alan Walkington | last post by:
Folks: How can I get an /exec'ed/ process to run in the background on an XP box? I have a monitor-like process which I am starting as 'exec("something.exe");' and, of course the exec function blocks until something.exe terminates. Just what I /don't/ want. (Wouldn't an & be nice here! Sigh) I need something.exe to disconnect and run in the background while I
1
3704
by: John Ryan | last post by:
What PHP code would I use to check if submitted sites to my directory actually exist?? I want to use something that can return the server code to me, ie HTTP 300 OK, or whatever. Can I do this with sockets??
10
4224
by: James | last post by:
What is the best method for creating a Web Page that uses both PHP and HTML ? <HTML> BLA BLA BLA BLA BLA
1
3638
by: joost | last post by:
Hello, I'm kind of new to mySQL but more used to Sybase/PHP What is illegal about this query or can i not use combined query's in mySQL? DELETE FROM manufacturers WHERE manufacturers_id NOT IN ( SELECT manufacturers_id FROM products )
3
3491
by: presspley | last post by:
I have bought the book on advanced dreamweaver and PHP recently. I have installed MySQL and PHP server but am getting an error on the $GET statement show below. It says there is a problem with the variable $GET but $GET is not a variable, I thought it came from the page that calls the PHP file? if(($_GET)==""){ this gets an error
2
106616
by: sky2070 | last post by:
i have two file with jobapp.html calling jobapp_action.php <HTML> <!-- jobapp.html --> <BODY> <H1>Phop's Bicycles Job Application</H1> <P>Are you looking for an exciting career in the world of cyclery? Look no further! </P> <FORM NAME='frmJobApp' METHOD=post ACTION="jobapp_action.php"> Please enter your name:
0
9275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9872
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9713
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8713
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7248
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5142
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3358
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.