Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Binding a DropDownList in DetailsView

Reply
Thread Tools

Binding a DropDownList in DetailsView

 
 
JJ
Guest
Posts: n/a
 
      05-03-2007
Hi.

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

The code is something like:
<aspetailsView 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>

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

</aspropDownList>


<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


 
Reply With Quote
 
 
 
 
JJ
Guest
Posts: n/a
 
      05-03-2007
Its ok - my mistake - the data was coming from the database jumbled up.....


"JJ" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi.
>
> I am having trouble getting a dropdownlist to work properly in a
> detailsview:
>
> The code is something like:
> <aspetailsView 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>
>
> <aspropDownList 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">
>
> </aspropDownList>
>
>
> <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
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DetailsView and DropdownList binding viktor ASP .Net 0 08-13-2007 08:31 PM
Re-Binding A DropDownList Within A DetailsView 47computers@gmail.com ASP .Net 0 03-23-2007 08:14 PM
DetailsView - Changing to Insert Mode (Not By Using the Insert Button In the DetailsView Control) Feege ASP .Net Web Controls 0 12-20-2005 12:28 AM
DetailsView Data Binding Andrew Robinson ASP .Net 2 10-10-2005 11:09 AM
Binding a textbox to a detailsview in asp.net 2.0 =?Utf-8?B?Q2VyaV9EYXZpZXM=?= ASP .Net 0 03-22-2005 06:11 PM



Advertisments