DropDownList in a DetailsView

Last post 10-22-2007 3:17 PM by toy. 9 replies.

Sort Posts:

  • DropDownList in a DetailsView

    11-17-2006, 5:00 PM
    • Loading...
    • CSchnaars
    • Joined on 07-31-2006, 6:36 PM
    • Posts 6

    I am using ASP.NET 2.0 and Visual Studio 2005.

    I have a DetailsView that the user can use to view and edit a record. One of these fields has only 7 possible values, so in edit mode, I want to switch to a dropdownlist. I had no problems doing this. I changed to a template field, then changed the textbox to a dropdownlist.

    What I want to do now is set the SelectedValue of that dropdownlist to match the existing value of the record being edited, but for the life of me, I can't figure out how to do this.

    First, I am confused about whether SelectedValue should be showing up as a property of asp:dropdownlist in the page design (not code behind). For me, it doesn't. I have seen many posts suggesting something like SelectedValue='<%# Bind("OrgType") %>' and assume that either this construction is not available in asp.net 2.0 or that I have a bad setting somewhere.

    I have tried a few variations of FindControl, but nothing I've tried is working, including some suggestions from a similar post earlier today:

    My Detailsview is called DetailsView1. The DropDownList (DropDownList1) is in the <EditItemTemplate>. Label7 is used in the <ItemTemplate>. The Text and Value properties for the seven items in the dropdownlist are identical text values.

    Thanks for any suggestions.

     

    Chris

  • Re: DropDownList in a DetailsView

    11-18-2006, 12:43 AM
    Answer
    • Loading...
    • pkellner
    • Joined on 11-12-2004, 10:42 AM
    • San Jose, California
    • Posts 3,441
    • Moderator
      TrustedFriends-MVPs

    You've got everything right on how to do it.

    You are putting SelectedValue='<%# Bind("OrgType") %>' as an attribute of the dropdownlist?  I've got some example of something similar on my blog.  (that is, how to show just a label with just the selectedvalue which is actually in the database) on my blog at the URL below.

    http://peterkellner.net/2006/10/27/smalllistaccessimproved/

     I'm assuming that selectedvalue is the value that appears in the row of the gridview if you were just to display it as a label.  True?

    Peter Kellner
    http://73rdstreet.com and blogging at
    http://PeterKellner.net
    MVP, ASP.NET
  • Re: DropDownList in a DetailsView

    11-19-2006, 8:18 AM
    • Loading...
    • andreDotNet
    • Joined on 11-19-2006, 3:46 AM
    • Posts 5
    CSchnaars:

    First, I am confused about whether SelectedValue should be showing up as a property of asp:dropdownlist in the page design (not code behind). For me, it doesn't. I have seen many posts suggesting something like SelectedValue='<%# Bind("OrgType") %>' and assume that either this construction is not available in asp.net 2.0 or that I have a bad setting somewhere.

    Yes, it's a property of asp:dropdownlist. Intellisense does not show it for some reason (I'm using VWD2005EE)., so just type it up, like this:

    <

    asp:DropDownList ID="DropDown1" runat="server" SelectedValue='<%# Bind("FieldName") %>'>

    It should work.

  • Re: DropDownList in a DetailsView

    11-20-2006, 8:51 AM
    • Loading...
    • CSchnaars
    • Joined on 07-31-2006, 6:36 PM
    • Posts 6

    Thanks very much. Just typing SelectedValue in with a bind statement worked flawlessly. I just wish I'd thought to try that.

     

    chris

  • Re: DropDownList in a DetailsView

    01-18-2007, 4:18 AM
    • Loading...
    • bhav27
    • Joined on 06-07-2006, 4:10 PM
    • Posts 69
    andreDotNet:
    CSchnaars:

    First, I am confused about whether SelectedValue should be showing up as a property of asp:dropdownlist in the page design (not code behind). For me, it doesn't. I have seen many posts suggesting something like SelectedValue='<%# Bind("OrgType") %>' and assume that either this construction is not available in asp.net 2.0 or that I have a bad setting somewhere.

    Yes, it's a property of asp:dropdownlist. Intellisense does not show it for some reason (I'm using VWD2005EE)., so just type it up, like this:

    <asp:DropDownList ID="DropDown1" runat="server" SelectedValue='<%# Bind("FieldName") %>'>

    It should work.

     

    I tried this but there is no  SelectedValue property in dropdownlist at design time.

  • Re: DropDownList in a DetailsView

    02-14-2007, 7:06 AM
    • Loading...
    • Sohnee
    • Joined on 02-02-2007, 10:18 PM
    • UK
    • Posts 491

    Hi bhav27,

     It doesn't show in design time - but it is valid. For some reason intellisense doesn't bring it up - so you have to type it!

  • Re: DropDownList in a DetailsView

    02-23-2007, 10:54 AM
    • Loading...
    • pmorrissey
    • Joined on 08-18-2006, 9:39 AM
    • Posts 4

    Hi all,

     This posting is just what I was looking for.  However, when I view the page, I get

    Parser Error Message: The 'SelectedValue' property cannot be set declaratively.

    I am using Visual Studio and IE7.

     I have the following code within the detailsview:

    <asp:TemplateField HeaderText="Security Code">

    <ItemTemplate>

    <asp:Literal runat="server" Text='<% Bind("security_code") %>'></asp:Literal>

    </ItemTemplate>

    <EditItemTemplate>

    <asp:DropDownList ID="security_list" runat="server" SelectedValue='<% Bind("security_code") %>'>

    <asp:ListItem Text="Customer" Value="Customer"></asp:ListItem>

    <asp:ListItem Text="Qubos" Value="Qubos"></asp:ListItem>

    </asp:DropDownList>

    </EditItemTemplate>

    </asp:TemplateField>

    Any ideas?

     

    Paul

  • Re: DropDownList in a DetailsView

    02-23-2007, 10:54 AM
    • Loading...
    • pmorrissey
    • Joined on 08-18-2006, 9:39 AM
    • Posts 4

    Hi all,

     This posting is just what I was looking for.  However, when I view the page, I get

    Parser Error Message: The 'SelectedValue' property cannot be set declaratively.

    I am using Visual Studio and IE7.

     I have the following code within the detailsview:

    <asp:TemplateField HeaderText="Security Code">

    <ItemTemplate>

    <asp:Literal runat="server" Text='<% Bind("security_code") %>'></asp:Literal>

    </ItemTemplate>

    <EditItemTemplate>

    <asp:DropDownList ID="security_list" runat="server" SelectedValue='<% Bind("security_code") %>'>

    <asp:ListItem Text="Customer" Value="Customer"></asp:ListItem>

    <asp:ListItem Text="Qubos" Value="Qubos"></asp:ListItem>

    </asp:DropDownList>

    </EditItemTemplate>

    </asp:TemplateField>

    Any ideas?

     

    Paul

  • Re: DropDownList in a DetailsView

    02-23-2007, 12:55 PM
    • Loading...
    • limno
    • Joined on 06-10-2005, 3:50 PM
    • Iowa, USA
    • Posts 3,430
    • Moderator
      TrustedFriends-MVPs
    Change to:  SelectedValue='<%# Bind("security_code") %>'>
    Limno

  • Re: DropDownList in a DetailsView

    10-22-2007, 3:17 PM
    • Loading...
    • toy
    • Joined on 12-13-2006, 10:42 AM
    • Posts 99

     thanks guys - good post

    i just thought i had a retarded version of VS 

    just a girl coder
Page 1 of 1 (10 items)
Microsoft Communities
Page view counter