How To Clone a DropDownList

Q

quiggle

I have a need to clone a dropDownList, passing all of the properties to the
new object, along with all of the originals eventHandlers.

I have been trying to use reflection to get all the properties, but continue
to get an error:
System.NullReferenceException: Object reference not set to an instance
of an object.

DropDownList clonedDropDown = new DropDownList();
System.Reflection.PropertyInfo[] properties = dd.GetType().GetProperties();
foreach(System.Reflection.PropertyInfo propInfo in properties )
{
object propValue = propInfo.GetValue(oldDropDown, null);
//(this is the line it complains about)
if ( propValue != null && propInfo.CanWrite)
propInfo.SetValue(clonedDropDown, propValue, null);
}

Also, I have no idea how to go about copying over the event handlers...Any
advice would be much appreciated!

Aimee
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top