How do I select item from DropDownList which contain only one item.

Last post 02-08-2007 11:31 AM by e_screw. 4 replies.

Sort Posts:

  • How do I select item from DropDownList which contain only one item.

    02-06-2007, 10:41 AM
    • Member
      37 point Member
    • pbarunkumar
    • Member since 12-04-2006, 3:45 PM
    • Dubai
    • Posts 54

    Hi guys,

                      I have a two dropdownlist box in my Webform. If I select item from dropdownlist1 then, the items are added to the dropdownlist2 box according the values of dropdownlist box1. The problem is if i select the dropdownbox2 which contains only one item, it is not Autopostback. How do i solve the problem? Any one give me idea. I am newbie to C#.

    Thanks

     

    Arun

    Regards,
    Arun
  • Re: How do I select item from DropDownList which contain only one item.

    02-06-2007, 11:04 AM
    • Contributor
      2,081 point Contributor
    • Rossoneri
    • Member since 11-09-2006, 8:57 PM
    • O-H I-O
    • Posts 435
    Insert a blank item into the DropDownList

    DropDownList.Items.Insert( 0, string.Empty )
  • Re: How do I select item from DropDownList which contain only one item.

    02-07-2007, 8:41 PM
    Hi,
    In this case, the only item in the dropdownlist will be selected automatically.
    Can you explain your requirement more specifically? There should be a better solution.
    Looking forward to your reply.
  • Re: How do I select item from DropDownList which contain only one item.

    02-08-2007, 8:53 AM
    • Member
      37 point Member
    • pbarunkumar
    • Member since 12-04-2006, 3:45 PM
    • Dubai
    • Posts 54

    Hi,

                The dropdownlist contains the parameter value. If I select the item then OnSelectedIndexChanged event fire. So some fields are fill up. Please give me idea.

    thanks

     

    Regards,
    Arun
  • Re: How do I select item from DropDownList which contain only one item.

    02-08-2007, 11:31 AM
    Answer
    • All-Star
      19,498 point All-Star
    • e_screw
    • Member since 10-20-2004, 1:22 PM
    • Women, Guitar, Russia, Billiards, Nature, .NET
    • Posts 3,893

    As said, add a dummy element. In the properties set AppendDataBoundItems = True, and in the down of properties windows -> Items , add an item

     

    1            <asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="True" AutoPostBack="true">
    2                <asp:ListItem Value="0">Select an item</asp:ListItem>
    3            </asp:DropDownList>
    
     
    Thanks

    Mark post(s) as "Answer" that helped you

    Electronic Screw
    Website||Blog||Dub@i.net
Page 1 of 1 (5 items)