By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,187 Members | 1,043 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,187 IT Pros & Developers. It's quick & easy.

Binding a DropDownList in DetailsView

P: n/a
JJ
Hi.

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

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">

<ItemTemplate>

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

</ItemTemplate>

<EditItemTemplate>

<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"
OnDataBound="ddlTitles_OnDataBound">

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

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
'Title'
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!

JJ
May 3 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
JJ
Its ok - my mistake - the data was coming from the database jumbled up.....
"JJ" <ab*@xyz.comwrote in message
news:eZ**************@TK2MSFTNGP04.phx.gbl...
Hi.

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

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">

<ItemTemplate>

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

</ItemTemplate>

<EditItemTemplate>

<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"
OnDataBound="ddlTitles_OnDataBound">

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

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
'Title'
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!

JJ

May 3 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.