How To Clone a DropDownList

Discussion in 'ASP .Net Building Controls' started by quiggle, Apr 9, 2004.

  1. quiggle

    quiggle Guest

    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!

    quiggle, Apr 9, 2004
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.