Saturday, March 24, 2012

Listbox - get item at certain index

Ok, end of the day and I must be getting tired or just not seeing it this time...
A simple listbox. It is populated. I need to simply read the value at index or postion 0 or 1 or whatever.
using C# have been trying something like this...

lstObjId.Items.IndexOf(i)
But of course it doesn't want to work.
And no, it will NOT be selected.
Been looking at all the other properties of the listbox, but just can't seem to find it.
Suggestions?
Thanks all,
Zath

lbxemployeelist.Items(i).Text or

lbxemployeelist.Items(i).value
one of these should work


No, I already tried those with no luck...
Funny thing is, I can get the value on the client side using JavaScript, but need it in the code behind...
var lb = document.getElementById('lbTest');
alert(lb.options[0].value);
Zath
In C#
lstObjId.Items[0].Text
That's actual code I used and it worked fine. So if that doesn't work, I'm as lost as you are.
You are right!
I forgot to convert something, the () over to [] because it's the array notation in C#.
It must be getting late....
Thanks!
Zath
Good, Happy Programming

0 comments:

Post a Comment