Re: Problems with ListBoxes

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Hermit Dave (hermitd.REMOVE_at_CAPS.AND.DOTS.hotmail.com)
Date: 09/19/04


Date: Sun, 19 Sep 2004 22:00:04 +0100

as long as you insert them using
if(!Page.IsPostback)
{
     // read from xml and load the items
}

you should be alright.
infact i am getting the values for selected index correctly using your code.

-- 
Regards,
Hermit Dave
(http://hdave.blogspot.com)
"John O'Donnell" <csharpconsulting@nospam-hotmail.com-nospam> wrote in
message news:unqE7monEHA.2680@TK2MSFTNGP15.phx.gbl...
> the problem seems to be when i add values in code
>
> i tried to run my code with values already entered into the ListBox
> collection and it works fine. If i add values through the page_load..these
> values fail to return a selectedindex etc.
>
> closer to the issue but not complete. I am reading an xml file and loading
> text values into the Listbox by doing ListBox.Items.Add("item1") etc
>
> any ideas why the selectedvalue or index fails on these values but not
ones
> entered directly into the control?
>
>
> "Hermit Dave" <hermitd.REMOVE@CAPS.AND.DOTS.hotmail.com> wrote in message
> news:uTDzGionEHA.3968@TK2MSFTNGP11.phx.gbl...
> > try using SelectedValue. I just ran your code after modifying the
> > selectedindex.tostring with selectedvalue and it works fine
> >
> > BTW. you have assigned "Starting" & "Finished" values to textbox before
> and
> > after. Since its on postback the user will never see "Starting". The
page
> is
> > rendered on completion when you have assigned "Finished".
> >
> > -- 
> >
> > Regards,
> >
> > Hermit Dave
> > (http://hdave.blogspot.com)
> > "John O'Donnell" <csharpconsulting@nospam-hotmail.com-nospam> wrote in
> > message news:eIVFyWonEHA.3324@TK2MSFTNGP15.phx.gbl...
> > > yes i selected an item before hitting the button.
> > > however when the button accesses the selectedindex property of the
> listbox
> > i
> > > always get a -1 ie nothing selected.
> > >
> > > the weird part if i can select the listbox items using ListBox1[1] etc
> etc
> > > so i can access the values of the listbox but not get a selecteditem
> > >
> > >
> > >
> > >
> > > "Hermit Dave" <hermitd.REMOVE@CAPS.AND.DOTS.hotmail.com> wrote in
> message
> > > news:uWd$LsnnEHA.2140@TK2MSFTNGP11.phx.gbl...
> > > > did you actually select any item before doing a postback with button
> > click
> > > ?
> > > > anyways post your code, its always easier to read the code than
having
> > to
> > > > guess %>)
> > > >
> > > > -- 
> > > >
> > > > Regards,
> > > >
> > > > Hermit Dave
> > > > (http://hdave.blogspot.com)
> > > > "John O'Donnell" <csharpconsulting@nospam-hotmail.com-nospam> wrote
in
> > > > message news:u1KPwinnEHA.1152@TK2MSFTNGP11.phx.gbl...
> > > > > Simple problem (i hope)
> > > > >
> > > > > I have a web form with a listbox control on it. on the page load i
> > added
> > > a
> > > > > few items to the listbox by doing ListBox1.Items.Add("item1"); etc
> > > > >
> > > > > now when i click my button on the form i want to to get the value
of
> > the
> > > > > selected item and put in the text of a text box.
> > > > >
> > > > > if i reference the items directly ie
> > > textbox1.text=ListBox1.Items[0].Text
> > > > > etc it works but I cannot seem to find a way to use
> > > ListBox1.SelectedValue
> > > > > or SelectedIndex as this returns -1 ie nothing selected?
> > > > >
> > > > > any input on this one?
> > > > >
> > > > > thanks
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>

Quantcast