Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0
This is the forum to discuss the Wrox book ASP.NET 2.0 Website Programming: Problem - Design - Solution by Marco Bellinaso; ISBN: 9780764584640
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 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
  #1 (permalink)  
Old March 26th, 2007, 07:10 PM
Registered User
 
Join Date: Mar 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Re-Binding A Dropdownlist In A DetailsView

I'm implementing many of the lessons from this book in a website project I've been working on, and one of the things that's giving me a bit of trouble is a little extra twist on the DetailsView for the addeditarticle.aspx page.

Instead of having text fields for the location information for Country and State, I have Dropdownlists populated from another provider I wrote for getting data from a source of reference information. The list of states should re-bind when a different country is selected.

The code snippet for these rows in the DetailsView is as follows (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="dropDownListCountry" 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="dropDownListCountry" PropertyName="SelectedValue" Name="countryID" Type="Int32" DefaultValue="225" />
      </SelectParameters>
    </asp:ObjectDataSource>
    <asp:DropDownList ID="dropDownListState" runat="server" Width="99%" SelectedValue='<%# Bind("StateID") %>' DataSourceID="objStates" DataTextField="Name" DataValueField="ID" />
  </EditItemTemplate>
</asp:TemplateField>

As you can imagine, the Dropdownlist for countries posts back, which should cause the page to reload and re-populate the ObjectDataSource for states using the new selected value of the country as a parameter. However, upon reloading, the page throws the following exception:

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

This method is working fine on a page with a manually-created form, but within a parent control, such as a DetailsView, this error is being thrown. Has anyone managed something like this, or can anyone offer any advice on the matter? Thanks.


Regards,
David



Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing DropDownList in DetailsView firblazer ASP.NET 3.5 Basics 2 June 21st, 2008 06:48 AM
Cannot bind from DropDownList to DetailsView kiekar ASP.NET 2.0 Basics 0 February 19th, 2008 09:26 PM
Linking two Dropdownlist in DetailsView tna55 ASP.NET 2.0 Basics 0 February 12th, 2007 10:29 AM
DropDownList in side the DetailsView ndc550 ASP.NET 2.0 Basics 0 October 19th, 2006 05:10 PM
dropdownlist value into detailsview: how? hertendreef ASP.NET 2.0 Professional 0 June 26th, 2006 01:54 AM





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