Search code examples
javascript.net-3.5listbox-control

asp:ListBox control selecting a row using javascript


I have an asp:ListBox control on my web page. I am trying to select an item in the list using javascript. After looking at the underlying structure I have tried:

catListBoxCtl[0].Selected = true;

Which does indeed set the 'selected' value to true but it doesn't highlight the appropriate row. I am just trying to replicate what a user does when you select a row using a mouse. How do you select a row programatically so that it get's highlighted etc?

Thanks.


Solution

  • I think you're missing the reference to the options. Try:

    catLIstBoxCtl.options[0].selected = true;