Binding a DropDownList in DetailsView

Discussion in 'ASP .Net' started by JJ, May 3, 2007.

  1. JJ

    JJ Guest

    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
     
    JJ, May 3, 2007
    #1
    1. Advertising

  2. JJ

    JJ Guest

    Its ok - my mistake - the data was coming from the database jumbled up.....


    "JJ" <> wrote in message
    news:...
    > 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
    >
     
    JJ, May 3, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Q2VyaV9EYXZpZXM=?=

    Binding a textbox to a detailsview in asp.net 2.0

    =?Utf-8?B?Q2VyaV9EYXZpZXM=?=, Mar 22, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    990
    =?Utf-8?B?Q2VyaV9EYXZpZXM=?=
    Mar 22, 2005
  2. Andrew Robinson

    DetailsView Data Binding

    Andrew Robinson, Sep 30, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    15,083
    Steven Cheng[MSFT]
    Oct 10, 2005
  3. Replies:
    0
    Views:
    486
  4. viktor
    Replies:
    0
    Views:
    541
    viktor
    Aug 13, 2007
  5. Feege
    Replies:
    0
    Views:
    472
    Feege
    Dec 20, 2005
Loading...

Share This Page