Binding a DropDownList in DetailsView




I am having trouble getting a dropdownlist to work properly in a

The code is something like:
<asp:DetailsView ID="dvwSubscriber" runat="server" AutoGenerateRows="False"

DataKeyNames="ID" DataSourceID="objCurrentSubscriber" DefaultMode="Insert"
HeaderText="Subscriber Details">

<asp:TemplateField HeaderText="Title" SortExpression="Title">


<asp:Label ID="lblTitle" runat="server" Text='<%# Eval("Title")



<asp:DropDownList runat="server" ID="ddlTitles"
DataSourceID="objTitles" SkinID="CenCol_dd_Lg_WithVal"
CssClass="input_box_text" DataTextField="text"

DataValueField="value" SelectedValue='<%# Bind("Title") %>'
Width="100%" ValidationGroup="EditProfile" AppendDataBoundItems="True"


<asp:ObjectDataSource ID="objTitles" runat="server"
SelectMethod="GetTitlesDataview" TypeName="MyNamespace.Helpers"
OnObjectCreated ="objTitles_ObjectCreated" >


This code results in an error when I try to load a row into the detailsview:

'ddlTitles' has a SelectedValue which is invalid because it does not exist
in the list of items.
Parameter name: value'

Yet the current Row in objCurrentSubscriber does appear to match one of the
values in objTitles.

objCurrentSubscriber is retrieved from an SQL table has a column named
objTitlesis a dataview that I programmatically construct from array string .
The Columns are 'text' and 'value' and, in effect are both the same (i.e.
(Mr, Mr), (Mrs, Mrs), etc)

I basically want the dropdown to show the correct entry for the detailsview
current row when in Edit mode - i.e. objCurrentSubscriber 's current row has
a 'Title' set to 'Mrs', so the dropdownlist should display 'Mrs'. When in
insert mode, the dropdownlist will show the options from objTitles.

Sounds simple but can I achieve it!?!

Please help!



Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question