-2

I have a drop down list with multiple values, I am pulling the values from a database table. This is working fine. I am trying to insert a new ListItem. I can get it to add the New ListItem with a single value. Example:

ListTest.Items.Insert(0, new ListItem("Test", "THIS"));

This gives the value of "THIS", but I am needing it to have a value of "This and That and Something Else". So if "TEST" is selected it would check the table for those 3 different items. Is this even possible?

Joker327
  • 55
  • 6
  • 3
    In order to answer this, of course we would need to know what your presentation technology is. I'm sure the answer isn't the same between WinForms, WPF, web, third-party, etc. Please don't make us guess. – rory.ap Jan 18 '17 at 21:41
  • everything is coded in asp and c#, website. – Joker327 Jan 18 '17 at 21:48
  • Please update your question with the appropriate tags, and remember to do so right away next time – rory.ap Jan 18 '17 at 21:58
  • You need to decide where to define the link between the one value and the three values that it maps to. Do you want to do it in c# code? Or perhaps you could do it in a table? – John Wu Jan 19 '17 at 00:20

2 Answers2

0

Here's one way with an extension method. This assumes you want to hardcode the relationship between the selected value and the values to look up.

public string[] GetImpliedSelectedValues(this listBox)
{
    switch case listBox.SelectedValue)
    {
        case "this_1_thru_3": 
            return new string[] {"this1", "this2", "this3"};         
            break;
        case "this_4_and_5":  
            return new string[] {"this4", "this5"};
            break;
        default:
            return new string[] {"nothing"};
    }
}

Then in your codebehind, just use

var valuesSelected = MyListBox.GetImpliedSelectedValues();
foreach (var v in valuesSelected)
{
    DoSomething(v);
}
John Wu
  • 44,075
  • 6
  • 37
  • 69
-1

i don t uderstand your question... i'll try you can use for example "This_That" and perform a split

Dans
  • 166
  • 6