Saturday, March 24, 2012

Trouble setting the selectedindex of a listbox

"John Kotuby" <johnk@dotnet.itags.org.powerlist.comwrote in message
news:%23ql%23buvFIHA.748@dotnet.itags.org.TK2MSFTNGP04.phx.gbl...

Quote:

Originally Posted by

It would be nice to be able to just "set" the SelectedValue. I am
wondering why that more direct route is not available.


lstState.SelectedValue = "CT"

or

lstState.Items.FindByValue("CT").Selected = True

--
Mark Rae
ASP.NET MVP
http://www.markrae.netThanks Mark,
I must have misread MSDN doc on that. I thought that only the SelectedIndex
was settable.

Yep there was a dumb mistake on my part. The State abbreviations were coming
from SQL lookup table in a field defined as Char(10) and I wasn't trimming
them. Some days I wonder where my head is.

"Mark Rae [MVP]" <mark@.markNOSPAMrae.netwrote in message
news:OrpZozvFIHA.4880@.TK2MSFTNGP03.phx.gbl...

Quote:

Originally Posted by

"John Kotuby" <johnk@.powerlist.comwrote in message
news:%23ql%23buvFIHA.748@.TK2MSFTNGP04.phx.gbl...
>

Quote:

Originally Posted by

>It would be nice to be able to just "set" the SelectedValue. I am
>wondering why that more direct route is not available.


>
lstState.SelectedValue = "CT"
>
or
>
lstState.Items.FindByValue("CT").Selected = True
>
>
--
Mark Rae
ASP.NET MVP
http://www.markrae.net


"John Kotuby" <JohnKotuby@.discussions.microsoft.comwrote in message
news:OBKQjIxFIHA.1388@.TK2MSFTNGP05.phx.gbl...

Quote:

Originally Posted by

I must have misread MSDN doc on that. I thought that only the
SelectedIndex was settable.


Easily done...

Quote:

Originally Posted by

Yep there was a dumb mistake on my part. The State abbreviations were
coming from SQL lookup table in a field defined as Char(10) and I wasn't
trimming them. Some days I wonder where my head is.


Are US state abbreviations ever anything other than two characters in
length...?

--
Mark Rae
ASP.NET MVP
http://www.markrae.net

0 comments:

Post a Comment