Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have one dropdown list that is filled from another dropdown list. This action takes place in many web pages of my site. I thought about creating a general method that takes some parameters which will fill the dependant dropdown list. The following is my proposed static method:
C#
public static  void FillDropDownList(string Parent_Ddl_Value,
                                     DropDownList Child_Ddl,
                                     ?? voidtofillchilddropdownlist);



I need to pass this void voidtofillchilddropdownlistas parameters & execute it? How can this be achieved.

Thanks for your time!
Posted
Updated 7-Sep-11 22:11pm
v2
Comments
Timberbird 8-Sep-11 3:55am    
Why void and not object?
Manfred Rudolf Bihy 8-Sep-11 4:14am    
Edit: Pre tags and clarity.

You cannot pass a void - a void is the absence of something.
Either pass a null, or (as I suspect) pass a delegate. The later is a "pointer to a method" that can be executed in FillDropDownList to do the actual filling: MSDN can explain best how to do that. http://msdn.microsoft.com/en-us/library/ms173172.aspx[^]
 
Share this answer
 
I'm not sure your approach is correct here but your requirements are unclear. (Also, im guessing DropDownList is actually a winfows.forms.comboBox but since i cant gurantee that im going to make no assumptions about the exposed methods/properties)

do you:

  1. Want to copy the entire contents of one drop-down list to another?
    you should have the following arguments:

    • DropDownList sourceList
    • dropDownList destinationList

  2. want to copy a single value from one drop-down list to another
    you should have the following arguments:

    • object valueToCopy
    • dropDownList destinationList

  3. Want to copy a contiguous range of values from one drop-down list to another:
    you should have the following arguments:

    • DropDownList sourceList
    • dropDownList destinationList
    • int firstValueIndex
    • int lastValueindex

  4. Want to copy a non-contiguous range of values from one drop-down list to another:
    you should have the following arguments:

    • DropDownList sourceList
    • dropDownList destinationList
    • int[] indicesToCopy



I hope that helps you some!
 
Share this answer
 
v3
Comments
Manfred Rudolf Bihy 8-Sep-11 4:54am    
Edit: Added ol/ul for indentation.

OP was actually very specific about having a web application, so it's not abaout winforms. :)
GParkings 8-Sep-11 5:06am    
doh! my bad, blame it on caffeine deficiency.

Thanks for the catch, and the formatting
As OriginalGriff[^] already mentioned it's most likely that it is delegates that you're after. You still missed telling us what the signature of that delegate is though, apart from the fact that the method is not supposed to return anything. I take it then, that this method is called solely on the purpose of it's side effect.

Please elaborate on your question and tell us what you're trying to achieve by calling this method which is passed in via a delegate and I will update my solution in accordance to the added information you'll supply. Use the link Improve question to improve your question.

Best Regards,

—MRB
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900