Add Code and decode to listbox

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Simon

    Add Code and decode to listbox

    Newbie alert!
    I have a webform listbox with what I am sure is a common requirement. I wish
    to store a list of values but display a "translatio n" or decode. An example
    would be 1, 2, 3, 4 and One, Two, Three, Four

    I created

    class ListBoxSpecial
    {
    public string Code;
    public string Decode;

    public override string ToString()
    {
    return Decode;
    }

    public ListBoxSpecial (string Code, string Decode)
    {
    this.Code = Code;
    this.Decode = Decode;
    }

    I then populate the listbox, ListBox1 on page load. E.g. I loop round doing

    ListBox1.Items. Add(new ListBoxSpecial( myCode, MyDecode)

    I was hoping the ListBox would display
    One
    Two
    Three
    Four

    but when selected I could return "2" or whatever code/decode was
    appropriate. However when I try this I get the error
    The best overloaded method match for
    'System.Web.UI. WebControls.Lis tItemCollection .Add(string)' has some invalid
    arguments
    Argument '1': cannot convert from 'myproj.WebForm 1.ListBoxSpecia l' to
    'string'

    Any help would be gratefully received.

    Cheers!
    Simon



Working...