locked
Inherit from DropDownList and his ListItems RRS feed

  • Question

  • User-1379029596 posted

     Hello!

    I just try to extend the asp DropDownList and his ListItems, because the "Value" property isn't enough for me and I need a second "Value" property for e.g. "Value2".

    Here is the code for my inherited DropDownList:

     

    namespace My_WebControls
    {
    [DefaultProperty("Text")]
    [ToolboxData("<{0}:my_DropDownList runat=server></{0}:my_DropDownList>")]
    public class my_DropDownList : DropDownList
    {

    }
    }

     

    Here are my questions: 

    1. How can I create my own ListItems for my DropDownList with a new property for e.g. "Value2" ?

    2. When I can extend the ListItems with the new Property "Value2",  how can I create a property for my DropDownList like "SelectedValue2"?

     

    Thank you in advance and sry for me bad english! [;)]

    Best Regards

    DellaRocco

     

    Thursday, May 14, 2009 2:55 PM

Answers

  • User-2106054853 posted

    Hi,

    It's not easy to implement since ListItem is a sealed class.

    If you need a "SelectedValue2" why not use some tricks? You can use a symbol to separate two values and assign the entire string to ListItem.Value, such as:

    "Value1_Value2"

    You know the "_" will not appear in the data so it's safe to use it. In other cases where "_" might occur in your data you can use other weird alien word to separate real data.

    By spliting the string you can get both values.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 18, 2009 2:05 AM
  • User-1379029596 posted

    Thank your for your answer!

    When I look at it.....it's so simple! Shame on me! [;)]

    Best Regards

    DellaRocco

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 20, 2009 3:49 AM

All replies

  • User-2106054853 posted

    Hi,

    It's not easy to implement since ListItem is a sealed class.

    If you need a "SelectedValue2" why not use some tricks? You can use a symbol to separate two values and assign the entire string to ListItem.Value, such as:

    "Value1_Value2"

    You know the "_" will not appear in the data so it's safe to use it. In other cases where "_" might occur in your data you can use other weird alien word to separate real data.

    By spliting the string you can get both values.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 18, 2009 2:05 AM
  • User-1379029596 posted

    Thank your for your answer!

    When I look at it.....it's so simple! Shame on me! [;)]

    Best Regards

    DellaRocco

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 20, 2009 3:49 AM