473,486 Members | 2,424 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Web: 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:TemplateField HeaderText="Country" SortExpression="Country">
<ItemTemplate>
<asp:Label ID="lblCountry" runat="server" Text='<%#
Country.GetCountryByID(Convert.ToInt32(Eval("Count ryID"))).Name %>'></
asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:ObjectDataSource ID="objCountries" runat="server"
TypeName="Country" SelectMethod="GetCountries" />
<asp:DropDownList ID="ddlCountry" runat="server" Width="99%"
SelectedValue='<%# Bind("CountryID") %>' DataSourceID="objCountries"
DataTextField="Name" DataValueField="ID" AutoPostBack="true" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="State" SortExpression="State">
<ItemTemplate>
<asp:Label ID="lblState" runat="server" Text='<%#
State.GetStateByID(Convert.ToInt32(Eval("StateID") )).Name %>'></
asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:ObjectDataSource ID="objStates" runat="server"
TypeName="State" SelectMethod="GetStates">
<SelectParameters>
<asp:ControlParameter ControlID="ddlCountry"
PropertyName="SelectedValue" Name="countryID" Type="Int32"
DefaultValue="225" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:DropDownList ID="ddlState" runat="server" Width="99%"
SelectedValue='<%# Bind("StateID") %>' DataSourceID="objStates"
DataTextField="Name" DataValueField="ID" />
</EditItemTemplate>
</asp:TemplateField>

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:

"Databinding methods such as Eval(), XPath(), and Bind() can only be
used in the context of a databound control."

Can anyone offer any advice on why this might be happening?
Regards,
David

Mar 23 '07 #1
1 2058
47computers,
This is not a C# language group question, it should be posted to the
dotnet.framework.aspnet group.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"47*********@gmail.com" wrote:
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:TemplateField HeaderText="Country" SortExpression="Country">
<ItemTemplate>
<asp:Label ID="lblCountry" runat="server" Text='<%#
Country.GetCountryByID(Convert.ToInt32(Eval("Count ryID"))).Name %>'></
asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:ObjectDataSource ID="objCountries" runat="server"
TypeName="Country" SelectMethod="GetCountries" />
<asp:DropDownList ID="ddlCountry" runat="server" Width="99%"
SelectedValue='<%# Bind("CountryID") %>' DataSourceID="objCountries"
DataTextField="Name" DataValueField="ID" AutoPostBack="true" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="State" SortExpression="State">
<ItemTemplate>
<asp:Label ID="lblState" runat="server" Text='<%#
State.GetStateByID(Convert.ToInt32(Eval("StateID") )).Name %>'></
asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:ObjectDataSource ID="objStates" runat="server"
TypeName="State" SelectMethod="GetStates">
<SelectParameters>
<asp:ControlParameter ControlID="ddlCountry"
PropertyName="SelectedValue" Name="countryID" Type="Int32"
DefaultValue="225" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:DropDownList ID="ddlState" runat="server" Width="99%"
SelectedValue='<%# Bind("StateID") %>' DataSourceID="objStates"
DataTextField="Name" DataValueField="ID" />
</EditItemTemplate>
</asp:TemplateField>

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:

"Databinding methods such as Eval(), XPath(), and Bind() can only be
used in the context of a databound control."

Can anyone offer any advice on why this might be happening?
Regards,
David

Mar 23 '07 #2

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

Similar topics

0
2511
by: Phillip J. Eby | last post by:
PEP: 333 Title: Python Web Server Gateway Interface v1.0 Version: $Revision: 1.1 $ Last-Modified: $Date: 2004/08/27 17:30:09 $ Author: Phillip J. Eby <pje at telecommunity.com> Discussions-To:...
0
5579
by: Mike | last post by:
Sites using thumbnail preview for world wide web file navigation and searching. Below are list of sites that are either researching or providing thumbnail preview images for online web...
2
6384
by: Carlos G Benevides | last post by:
I have a ASP.Net web application that has two assemblies that run under com+. Under Windows 2000 the two assemblies are added to com+ automatically when instantiated from the web site. For this...
0
2912
by: Bill Burwell | last post by:
I am converting a VB6 WebClass application to VB.Net. Used the VB upgrade tool to do the conversion - and it left me a lot of little code things to do. Did those code things and got my app to...
4
8638
by: Trond A. S. Andersen | last post by:
Hi, all! I'm trying to use the System.Web.Mail. "package" combinded with System.Web.Mail.SmtpMail in order to send MS Excel spreadsheets attached to mail messages. However, sending one single...
0
2132
by: Diego F. | last post by:
I've been days with that. I'm trying to work with web services sending and returning objects, and the web service must store some objects. - My first try (the most obvious in my opinion) was to use...
1
3589
by: Gregory Hassett | last post by:
Hi, I have a web service called GetComputerNameAndDescription which I can call from the main thread of my app. If I call it from a separate thread, however, it hangs on the call to Invoke() -- but...
0
1169
by: Baruaa | last post by:
hi i m asheesh , can any on ehelp me about this error. Line 57: --> Line 58: <httpHandlers> Line 59: <add verb="*" path="*.vb" type="System.Web.HttpNotFoundHandler,System.Web" />
4
2906
by: Sanjay | last post by:
I have written a web service to return information from the database. This works and the data is returned in XML format from the database and displayed on the web page as well when this web service...
2
7387
by: =?Utf-8?B?YW5vbg==?= | last post by:
I am not sure if this is the right forum. Environment : Windows server 2008, IIS 7.0 I get the 'Could not load the file or assembly 'blowery.web.httpCompress' or one of its dependencies. The...
0
7175
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...
0
7330
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...
1
4865
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...
0
4559
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...
0
3070
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...
0
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1378
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
598
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
262
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.