Multiple DropDownLists

Discussion in 'ASP .Net' started by Igor, Jun 12, 2008.

  1. Igor

    Igor Guest

    Hello

    I have the following problem. I have three drop down lists on my page. They
    are filled with data from a database. Initially only the first one is
    enabled. The next one is enebled when user selects an item from the first
    one -- it is then filled with data specific to the selection in the drop
    down list above. The same with the third one. For each drop down list the
    first item is always "--select an item--" (as described here:
    http://weblogs.asp.net/scottgu/archive/2006/01/29/436804.aspx). To enable
    that I had to set the AppendDataBoundItems property for all three drop down
    lists to "true". Unfortunatelly, when a user selects an item from the first
    drop down list, the second one gets filled with item "--select an item--"
    and data from the database. But if the user changes their mind and selects
    different item from the first list (or list above in the structure) the next
    drop down list gets filled with new data, but, because of the
    AppendDataBoundItems property set to "true", previous data remains in the
    list. Thus, I must clear list(s) when user makes change to the selection
    above in the structure. How can I do this?

    Kind regards

    IgorM
     
    Igor, Jun 12, 2008
    #1
    1. Advertising

  2. Igor

    David Wier Guest

    ddl.items.clear

    David Wier
    http://aspnet101.com
    http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with no
    bloated markup


    "Igor" <> wrote in message
    news:...
    > Hello
    >
    > I have the following problem. I have three drop down lists on my page.
    > They are filled with data from a database. Initially only the first one is
    > enabled. The next one is enebled when user selects an item from the first
    > one -- it is then filled with data specific to the selection in the drop
    > down list above. The same with the third one. For each drop down list the
    > first item is always "--select an item--" (as described here:
    > http://weblogs.asp.net/scottgu/archive/2006/01/29/436804.aspx). To enable
    > that I had to set the AppendDataBoundItems property for all three drop
    > down lists to "true". Unfortunatelly, when a user selects an item from the
    > first drop down list, the second one gets filled with item "--select an
    > item--" and data from the database. But if the user changes their mind and
    > selects different item from the first list (or list above in the
    > structure) the next drop down list gets filled with new data, but, because
    > of the AppendDataBoundItems property set to "true", previous data remains
    > in the list. Thus, I must clear list(s) when user makes change to the
    > selection above in the structure. How can I do this?
    >
    > Kind regards
    >
    > IgorM
     
    David Wier, Jun 12, 2008
    #2
    1. Advertising

  3. Igor

    Igor Guest

    Hi

    I didn't make myself clear enough. Where should I put it in the code ? I
    tried putting it in SelectedIndexChanged events of particular drop down
    lists as well as PageLoad event but than I had a problem with a statement
    that selects first item (the one with "--select item --" text ) in the drop
    down lists below in the hierarchy because it fired exceptions. By
    ddl.items.clear the first item, the "--select item--" is also cleares, and
    it is not added again in postbacks.

    Kind regars
    IgorM

    "David Wier" <> wrote in message
    news:%...
    > ddl.items.clear
    >
    > David Wier
    > http://aspnet101.com
    > http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with
    > no bloated markup
    >
    >
    > "Igor" <> wrote in message
    > news:...
    >> Hello
    >>
    >> I have the following problem. I have three drop down lists on my page.
    >> They are filled with data from a database. Initially only the first one
    >> is enabled. The next one is enebled when user selects an item from the
    >> first one -- it is then filled with data specific to the selection in the
    >> drop down list above. The same with the third one. For each drop down
    >> list the first item is always "--select an item--" (as described here:
    >> http://weblogs.asp.net/scottgu/archive/2006/01/29/436804.aspx). To enable
    >> that I had to set the AppendDataBoundItems property for all three drop
    >> down lists to "true". Unfortunatelly, when a user selects an item from
    >> the first drop down list, the second one gets filled with item "--select
    >> an item--" and data from the database. But if the user changes their mind
    >> and selects different item from the first list (or list above in the
    >> structure) the next drop down list gets filled with new data, but,
    >> because of the AppendDataBoundItems property set to "true", previous data
    >> remains in the list. Thus, I must clear list(s) when user makes change to
    >> the selection above in the structure. How can I do this?
    >>
    >> Kind regards
    >>
    >> IgorM

    >
    >
     
    Igor, Jun 12, 2008
    #3
  4. Igor

    David Wier Guest

    You should put it anywhere you need it, in any event handler, just before
    you're populating the ddl.
    Anothere thing - if you're populating any ddls in the Page_Load event, be
    sure to surround that population with an if/then/Postback block

    David Wier
    http://aspnet101.com
    http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with no
    bloated markup


    "Igor" <> wrote in message
    news:...
    > Hi
    >
    > I didn't make myself clear enough. Where should I put it in the code ? I
    > tried putting it in SelectedIndexChanged events of particular drop down
    > lists as well as PageLoad event but than I had a problem with a statement
    > that selects first item (the one with "--select item --" text ) in the
    > drop down lists below in the hierarchy because it fired exceptions. By
    > ddl.items.clear the first item, the "--select item--" is also cleares, and
    > it is not added again in postbacks.
    >
    > Kind regars
    > IgorM
    >
    > "David Wier" <> wrote in message
    > news:%...
    >> ddl.items.clear
    >>
    >> David Wier
    >> http://aspnet101.com
    >> http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with
    >> no bloated markup
    >>
    >>
    >> "Igor" <> wrote in message
    >> news:...
    >>> Hello
    >>>
    >>> I have the following problem. I have three drop down lists on my page.
    >>> They are filled with data from a database. Initially only the first one
    >>> is enabled. The next one is enebled when user selects an item from the
    >>> first one -- it is then filled with data specific to the selection in
    >>> the drop down list above. The same with the third one. For each drop
    >>> down list the first item is always "--select an item--" (as described
    >>> here: http://weblogs.asp.net/scottgu/archive/2006/01/29/436804.aspx). To
    >>> enable that I had to set the AppendDataBoundItems property for all three
    >>> drop down lists to "true". Unfortunatelly, when a user selects an item
    >>> from the first drop down list, the second one gets filled with item
    >>> "--select an item--" and data from the database. But if the user changes
    >>> their mind and selects different item from the first list (or list above
    >>> in the structure) the next drop down list gets filled with new data,
    >>> but, because of the AppendDataBoundItems property set to "true",
    >>> previous data remains in the list. Thus, I must clear list(s) when user
    >>> makes change to the selection above in the structure. How can I do this?
    >>>
    >>> Kind regards
    >>>
    >>> IgorM

    >>
    >>

    >
     
    David Wier, Jun 12, 2008
    #4
  5. Igor

    Igor Guest

    Still don't know how to get the first item to be "--select value--" in code
    behind if I cannot use the <asp:ListItem Text="-- select value --"
    Value="">.


    "David Wier" <> wrote in message
    news:...
    > You should put it anywhere you need it, in any event handler, just before
    > you're populating the ddl.
    > Anothere thing - if you're populating any ddls in the Page_Load event, be
    > sure to surround that population with an if/then/Postback block
    >
    > David Wier
    > http://aspnet101.com
    > http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with
    > no bloated markup
    >
    >
    > "Igor" <> wrote in message
    > news:...
    >> Hi
    >>
    >> I didn't make myself clear enough. Where should I put it in the code ? I
    >> tried putting it in SelectedIndexChanged events of particular drop down
    >> lists as well as PageLoad event but than I had a problem with a statement
    >> that selects first item (the one with "--select item --" text ) in the
    >> drop down lists below in the hierarchy because it fired exceptions. By
    >> ddl.items.clear the first item, the "--select item--" is also cleares,
    >> and it is not added again in postbacks.
    >>
    >> Kind regars
    >> IgorM
    >>
    >> "David Wier" <> wrote in message
    >> news:%...
    >>> ddl.items.clear
    >>>
    >>> David Wier
    >>> http://aspnet101.com
    >>> http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML
    >>> with no bloated markup
    >>>
    >>>
    >>> "Igor" <> wrote in message
    >>> news:...
    >>>> Hello
    >>>>
    >>>> I have the following problem. I have three drop down lists on my page.
    >>>> They are filled with data from a database. Initially only the first one
    >>>> is enabled. The next one is enebled when user selects an item from the
    >>>> first one -- it is then filled with data specific to the selection in
    >>>> the drop down list above. The same with the third one. For each drop
    >>>> down list the first item is always "--select an item--" (as described
    >>>> here: http://weblogs.asp.net/scottgu/archive/2006/01/29/436804.aspx).
    >>>> To enable that I had to set the AppendDataBoundItems property for all
    >>>> three drop down lists to "true". Unfortunatelly, when a user selects an
    >>>> item from the first drop down list, the second one gets filled with
    >>>> item "--select an item--" and data from the database. But if the user
    >>>> changes their mind and selects different item from the first list (or
    >>>> list above in the structure) the next drop down list gets filled with
    >>>> new data, but, because of the AppendDataBoundItems property set to
    >>>> "true", previous data remains in the list. Thus, I must clear list(s)
    >>>> when user makes change to the selection above in the structure. How can
    >>>> I do this?
    >>>>
    >>>> Kind regards
    >>>>
    >>>> IgorM
    >>>
    >>>

    >>

    >
    >
     
    Igor, Jun 12, 2008
    #5
  6. Igor

    Mark Elliott Guest

    Would something like the following work?

    DropDownList ddl = new DropDownList();
    ListItem li = new ListItem("--select item--");
    ddl.Items.Insert(li);

    On Thu, 12 Jun 2008 13:57:18 -0300, Igor <> wrote:

    > Still don't know how to get the first item to be "--select value--" in
    > code behind if I cannot use the <asp:ListItem Text="-- select value --"
    > Value="">.
    >
    >
    > "David Wier" <> wrote in message
    > news:...
    >> You should put it anywhere you need it, in any event handler, just
    >> before you're populating the ddl.
    >> Anothere thing - if you're populating any ddls in the Page_Load event,
    >> be sure to surround that population with an if/then/Postback block
    >>
    >> David Wier
    >> http://aspnet101.com
    >> http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML
    >> with no bloated markup
    >>
    >>
    >> "Igor" <> wrote in message
    >> news:...
    >>> Hi
    >>>
    >>> I didn't make myself clear enough. Where should I put it in the code ?
    >>> I tried putting it in SelectedIndexChanged events of particular drop
    >>> down lists as well as PageLoad event but than I had a problem with a
    >>> statement that selects first item (the one with "--select item --"
    >>> text ) in the drop down lists below in the hierarchy because it fired
    >>> exceptions. By ddl.items.clear the first item, the "--select item--"
    >>> is also cleares, and it is not added again in postbacks.
    >>>
    >>> Kind regars
    >>> IgorM
    >>>
    >>> "David Wier" <> wrote in message
    >>> news:%...
    >>>> ddl.items.clear
    >>>>
    >>>> David Wier
    >>>> http://aspnet101.com
    >>>> http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML
    >>>> with no bloated markup
    >>>>
    >>>>
    >>>> "Igor" <> wrote in message
    >>>> news:...
    >>>>> Hello
    >>>>>
    >>>>> I have the following problem. I have three drop down lists on my
    >>>>> page. They are filled with data from a database. Initially only the
    >>>>> first one is enabled. The next one is enebled when user selects an
    >>>>> item from the first one -- it is then filled with data specific to
    >>>>> the selection in the drop down list above. The same with the third
    >>>>> one. For each drop down list the first item is always "--select an
    >>>>> item--" (as described here:
    >>>>> http://weblogs.asp.net/scottgu/archive/2006/01/29/436804.aspx). To
    >>>>> enable that I had to set the AppendDataBoundItems property for all
    >>>>> three drop down lists to "true". Unfortunatelly, when a user selects
    >>>>> an item from the first drop down list, the second one gets filled
    >>>>> with item "--select an item--" and data from the database. But if
    >>>>> the user changes their mind and selects different item from the
    >>>>> first list (or list above in the structure) the next drop down list
    >>>>> gets filled with new data, but, because of the AppendDataBoundItems
    >>>>> property set to "true", previous data remains in the list. Thus, I
    >>>>> must clear list(s) when user makes change to the selection above in
    >>>>> the structure. How can I do this?
    >>>>>
    >>>>> Kind regards
    >>>>>
    >>>>> IgorM
    >>>>
    >>>>
    >>>

    >>
    >>

    >




    --
    Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
     
    Mark Elliott, Jun 12, 2008
    #6
  7. Perhaps you can use this free control to make your life easier:
    http://www.asp.net/AJAX/AjaxControlToolkit/Samples/CascadingDropDown/CascadingDropDown.aspx

    --
    I hope this helps,
    Steve C. Orr,
    MCSD, MVP, CSM, ASPInsider
    http://SteveOrr.net
    http://iPhonePlaza.net


    "Igor" <> wrote in message
    news:...
    > Hello
    >
    > I have the following problem. I have three drop down lists on my page.
    > They are filled with data from a database. Initially only the first one is
    > enabled. The next one is enebled when user selects an item from the first
    > one -- it is then filled with data specific to the selection in the drop
    > down list above. The same with the third one. For each drop down list the
    > first item is always "--select an item--" (as described here:
    > http://weblogs.asp.net/scottgu/archive/2006/01/29/436804.aspx). To enable
    > that I had to set the AppendDataBoundItems property for all three drop
    > down lists to "true". Unfortunatelly, when a user selects an item from the
    > first drop down list, the second one gets filled with item "--select an
    > item--" and data from the database. But if the user changes their mind and
    > selects different item from the first list (or list above in the
    > structure) the next drop down list gets filled with new data, but, because
    > of the AppendDataBoundItems property set to "true", previous data remains
    > in the list. Thus, I must clear list(s) when user makes change to the
    > selection above in the structure. How can I do this?
    >
    > Kind regards
    >
    > IgorM
     
    Steve C. Orr [MCSD, MVP, CSM, ASP Insider], Jun 12, 2008
    #7
  8. Igor

    mahesh reddy Guest

    i m also facing same prblm

    > On Thursday, June 12, 2008 9:59 AM Igor wrote:


    > Hello
    >
    > I have the following problem. I have three drop down lists on my page. They
    > are filled with data from a database. Initially only the first one is
    > enabled. The next one is enebled when user selects an item from the first
    > one -- it is then filled with data specific to the selection in the drop
    > down list above. The same with the third one. For each drop down list the
    > first item is always "--select an item--" (as described here:
    > http://weblogs.asp.net/scottgu/archive/2006/01/29/436804.aspx). To enable
    > that I had to set the AppendDataBoundItems property for all three drop down
    > lists to "true". Unfortunatelly, when a user selects an item from the first
    > drop down list, the second one gets filled with item "--select an item--"
    > and data from the database. But if the user changes their mind and selects
    > different item from the first list (or list above in the structure) the next
    > drop down list gets filled with new data, but, because of the
    > AppendDataBoundItems property set to "true", previous data remains in the
    > list. Thus, I must clear list(s) when user makes change to the selection
    > above in the structure. How can I do this?
    >
    > Kind regards
    >
    > IgorM



    >> On Thursday, June 12, 2008 10:22 AM David Wier wrote:


    >> ddl.items.clear
    >>
    >> David Wier
    >> http://aspnet101.com
    >> http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with no
    >> bloated markup



    >>> On Thursday, June 12, 2008 11:29 AM Igor wrote:


    >>> Hi
    >>>
    >>> I didn't make myself clear enough. Where should I put it in the code ? I
    >>> tried putting it in SelectedIndexChanged events of particular drop down
    >>> lists as well as PageLoad event but than I had a problem with a statement
    >>> that selects first item (the one with "--select item --" text ) in the drop
    >>> down lists below in the hierarchy because it fired exceptions. By
    >>> ddl.items.clear the first item, the "--select item--" is also cleares, and
    >>> it is not added again in postbacks.
    >>>
    >>> Kind regars
    >>> IgorM
    >>>
    >>> "David Wier" <> wrote in message
    >>> news:%...



    >>>> On Thursday, June 12, 2008 11:52 AM David Wier wrote:


    >>>> You should put it anywhere you need it, in any event handler, just before
    >>>> you're populating the ddl.
    >>>> Anothere thing - if you're populating any ddls in the Page_Load event, be
    >>>> sure to surround that population with an if/then/Postback block
    >>>>
    >>>> David Wier
    >>>> http://aspnet101.com
    >>>> http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with no
    >>>> bloated markup
    >>>>
    >>>>
    >>>> "Igor" <> wrote in message
    >>>> news:...



    >>>>> On Thursday, June 12, 2008 12:57 PM Igor wrote:


    >>>>> Still do not know how to get the first item to be "--select value--" in code
    >>>>> behind if I cannot use the <asp:ListItem Text="-- select value --"
    >>>>> Value="">.



    >>>>>> On Thursday, June 12, 2008 1:21 PM Mark Elliott wrote:


    >>>>>> Would something like the following work?
    >>>>>>
    >>>>>> DropDownList ddl = new DropDownList();
    >>>>>> ListItem li = new ListItem("--select item--");
    >>>>>> ddl.Items.Insert(li);
    >>>>>>
    >>>>>> On Thu, 12 Jun 2008 13:57:18 -0300, Igor <> wrote:
    >>>>>>
    >>>>>>
    >>>>>>
    >>>>>>
    >>>>>> --
    >>>>>> Using Opera's revolutionary e-mail client: http://www.opera.com/mail/



    >>>>>>> On Thursday, June 12, 2008 5:03 PM Steve C. Orr [MCSD, MVP, CSM, ASP Insider] wrote:


    >>>>>>> Perhaps you can use this free control to make your life easier:
    >>>>>>> http://www.asp.net/AJAX/AjaxControlToolkit/Samples/CascadingDropDown/CascadingDropDown.aspx
    >>>>>>>
    >>>>>>> --
    >>>>>>> I hope this helps,
    >>>>>>> Steve C. Orr,
    >>>>>>> MCSD, MVP, CSM, ASPInsider
    >>>>>>> http://SteveOrr.net
    >>>>>>> http://iPhonePlaza.net
    >>>>>>>
    >>>>>>>
    >>>>>>> "Igor" <> wrote in message
    >>>>>>> news:...



    >>>>>>> Submitted via EggHeadCafe
    >>>>>>> Twitter Search API with jQuery and JSONP
    >>>>>>> http://www.eggheadcafe.com/tutorial...twitter-search-api-with-jquery-and-jsonp.aspx
     
    mahesh reddy, Jan 25, 2011
    #8
    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. Darren

    Multiple DropDownLists

    Darren, Aug 18, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    422
    Steve C. Orr, MCSD
    Aug 18, 2003
  2. Craig Buchanan

    reuse SQLDataReader in multiple dropdownlists?

    Craig Buchanan, Jan 12, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    3,320
    Craig Buchanan
    Jan 15, 2004
  3. Angel.Net
    Replies:
    1
    Views:
    366
    =?Utf-8?B?Q3JhaWc=?=
    Jun 15, 2005
  4. RSH
    Replies:
    3
    Views:
    436
  5. Geoff Taylor

    Multiple dependent dropdownlists in whidbey

    Geoff Taylor, Aug 6, 2004, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    136
    Chandra Sekhar
    Aug 6, 2004
Loading...

Share This Page