Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Multiple dropdowns that share the same data

asp c# javascript dropdownlist data

This topic has been archived. This means that you cannot reply to this topic.
No replies to this topic

#1 Tchpowdog

Tchpowdog

    CC Regular

  • Member
  • PipPipPip
  • 44 posts

Posted 20 September 2016 - 07:14 AM

I will give an example to explain what I am doing -

 

This is my data:

UserID            Pet            Qty

1000               Dog           3

1000               Cat            1

1000               Bird            2

1000               Snake        0

 

On my webpage, I would like to have a variable amount of dropdownlists that share this data pool.  Each DDL will start with the following items:

- None

- Dog

- Cat

- Bird

- {it will not have a "Snake" item because the Snake Qty is 0}

 

Each DDL is initially set to selected item "None".

 

If DDL1 is changed to selected item "Cat", the "Cat" qty becomes 0 and the cat option is removed from all other DDLs.  What is the best/most efficient way to do this in ASP.NET??

 

Right now, I am loading the data into a hiddenfield and I'm handling all of the dynamics on page with Javascript.  When the page is saved, my server side script saves the data based on the hiddenfield value.  It's very confusing Javascript code, as one could imagine, there is a lot of rewriting to and repopulating.  The code seems to work great on Chrome and Edge but does not seem to execute on all browsers.  I need to fix this so I was wondering if there was a completely different and better way to do this.  Could I bind the data to the DDLs, perhaps?  If so, how do I handle the Qtys in that case?

 

Thanks in advance!