Re: DropDownList.FindByValue.Selected not working... help!
From: Eliyahu Goldin (removemeegoldin_at_monarchmed.com)
Date: 01/10/05
- Next message: Jeff B: "DESPERATE: FormsAuthentication Problem"
- Previous message: Jim Bancroft: "Re: Can I read code-behind info outside of asp.net?"
- In reply to: dhnriverside: "Re: DropDownList.FindByValue.Selected not working... help!"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 11 Jan 2005 00:04:39 +0200
It matters only for the ddl you are setting for. The second one just finds
that one of its item suddenly became selected without any calls to
SelectedIndex.
Eliyahu
"dhnriverside" <dan@musoswire.com> wrote in message
news:893673A8-7C6A-4F48-961D-0E8FEAF436F8@microsoft.com...
> But Im not using Item.Selected - i changed it to ddl.SelectedIndex= on
your
> recommendation. That's why I don't understand.........
>
> "Eliyahu Goldin" wrote:
>
> > because "Selected" is a property of ListItem, not of ddl. By setting
> > ..Selected, you don't select the item in the owner list, as in the
case.of
> > setting .SelectedItem. Rather you set the item on it's own, and the
owners
> > have to fight whether the item should be selected or no.
> >
> > Eliyahu
> >
> > "dhnriverside" <dan@musoswire.com> wrote in message
> > news:CE8194EA-0A0B-4FE2-9ADB-C0324158F6D7@microsoft.com...
> > > Hold on...
> > >
> > > How does selecting an item in one list make the list go "ah yes, but
I'm
> > > also in this list as well, so update it list too". ?!!
> > >
> > > The ListItem has no idea what list (or lists) it belongs to, so how
can it
> > > select itself in other lists?!
> > >
> > >
> > > "Eliyahu Goldin" wrote:
> > >
> > > > Aha, that explains it. Setting .Selected mark the item as selected.
And
> > if
> > > > the same item belongs to 2 ddls, the second one gets find itself
having
> > two
> > > > selected items since noone unselected the previous one.
> > > >
> > > > Thanks for a nice excercise.
> > > >
> > > > Eliyahu
> > > >
> > > > "dhnriverside" <dan@musoswire.com> wrote in message
> > > > news:82C8D9FC-2D39-417B-932B-916CECD68A92@microsoft.com...
> > > > > Okay..... that worked! But I'm not sure why...
> > > > >
> > > > > I changed the code that filled the DDLs so that it created 2
ListItem
> > > > > thingies, one called iSThisHour and iEThisHour. It worked great.
> > > > >
> > > > > So... why does using the same ListItem with 2 DDLs cause a
> > SelectedIndex =
> > > > > on one of the DDLs to change the SelectedIndex on the other DDL?
> > > > >
> > > > > Anyone enlighten me?
> > > > >
> > > > >
> > > > > "dhnriverside" wrote:
> > > > >
> > > > > > Hi Eliyahu,
> > > > > >
> > > > > > Right, I've changed all the .Selected to SelectedIndex and that
> > seems to
> > > > > > have got rid of the Multiple Select error thing.
> > > > > >
> > > > > > Stil lhaving trouble with the duplication though.. I've renamed
all
> > the
> > > > > > DDLs, moved things around, etc.
> > > > > >
> > > > > > The only thing I can think of is that the peice of code that
fills
> > the
> > > > DDLs
> > > > > > with the hours (09, 10, 11, 12, 13 etc) fills both boxes at the
same
> > > > time
> > > > > > using the same ListItem. eg...
> > > > > >
> > > > > > ListItem iThisHour = new ListItem();
> > > > > > iThisHour.Text = curHour.ToString();
> > > > > > iThisHour.Value = curHour.ToString();
> > > > > > ddlStartTimeHour.Items.Add(iThisHour);
> > > > > > ddlEndTimeHour.Items.Add(iThisHour);
> > > > > > iThisHour = null;
> > > > > >
> > > > > > Where curHour is the for loop counter.
> > > > > >
> > > > > > Could this be anything to do with it? Having looked at the code
> > again,
> > > > it
> > > > > > appears to be the only place where the 2 DDLs meet, as it were.
> > > > > >
> > > > > > Thoughts?
> > > > > >
> > > > > > Cheers
> > > > > >
> > > > > >
> > > > > > Dan
> > > > > >
> > > > > >
> > > > > > "Eliyahu Goldin" wrote:
> > > > > >
> > > > > > > Dan,
> > > > > > >
> > > > > > > I am not sure that .SelectedIndex and .Selected is the same.
> > ..Selected
> > > > is a
> > > > > > > property of just one item. It has no way of knowing what's
going
> > on
> > > > with the
> > > > > > > other items. Whereas .SelectedIndex is a property of ddl, and
the
> > ddl
> > > > can
> > > > > > > first unselect previously selected item.
> > > > > > >
> > > > > > > As far as your weird problem is concerned, it is very weird
> > indeed.
> > > > Check
> > > > > > > carefully the aspx, is there any way the ddls can refer to the
> > same
> > > > object?
> > > > > > >
> > > > > > > Eliyahu
> > > > > > >
> > > > > > > "dhnriverside" <dan@musoswire.com> wrote in message
> > > > > > > news:1453C11A-C86C-49B8-A35D-3798EFDBB96E@microsoft.com...
> > > > > > > > Hi Eliyahu,
> > > > > > > >
> > > > > > > > Thanks for the reply. Unfortunately that's even weirder.
> > > > > > > >
> > > > > > > > I understand the theory of the DDL, and I assume that
> > > > Items.FindByValue
> > > > > > > > gives u the index number, so doing .Selected = true is the
same
> > as
> > > > > > > > .SelectedIndex = x;
> > > > > > > >
> > > > > > > > However, I have tried it and got some very strange
behaviour...
> > > > Here's my
> > > > > > > > previous post on this topic, posted yesterday .....
> > > > > > > >
> > > > > > > > -------
> > > > > > > > OK, I'm getting a weird error trying to select a DDL item
based
> > on
> > > > what's
> > > > > > > > stored in the database.
> > > > > > > >
> > > > > > > > I have 4 DDLs on my aspx page...
> > > > > > > >
> > > > > > > > <asp:dropdownlist id="ddlStartTimeHour" runat="server" />
> > > > > > > > <asp:dropdownlist id="ddlEndTimeHour" runat="server" />
> > > > > > > > <asp:dropdownlist id="ddlStartTimeMinute" runat="server" />
> > > > > > > > <asp:dropdownlist id="ddlEndTimeMinute" runat="server" />
> > > > > > > >
> > > > > > > > these are declared in the C# as
> > > > > > > >
> > > > > > > > protected System.Web.UI.WebControls.DropDownList
> > ddlStartTimeHour;
> > > > > > > > protected System.Web.UI.WebControls.DropDownList
> > ddlStartTimeMinute;
> > > > > > > > protected System.Web.UI.WebControls.DropDownList
ddlEndTimeHour;
> > > > > > > > protected System.Web.UI.WebControls.DropDownList
> > ddlEndTimeMinute;
> > > > > > > >
> > > > > > > > They are populated on Page_load with a couple of for loops
(09,
> > 10,
> > > > 11 etc
> > > > > > > > for hour, 00,15,30,45 for minute). Then, Im trying to select
the
> > > > correct
> > > > > > > data
> > > > > > > > based on a DataReader as follows..
> > > > > > > >
> > > > > > > > string[] timeStart, timeEnd;
> > > > > > > > timeStart = dr["SessionTimeStart"].ToString().Split(':');
> > > > > > > > timeEnd = dr["SessionTimeEnd"].ToString().Split(':');
> > > > > > > >
> > > > > > > > ddlStartTimeHour.Items.FindByValue(timeStart[0]).Selected =
> > true;
> > > > > > > > ddlStartTimeMinute.Items.FindByValue(timeStart[1]).Selected
=
> > true;
> > > > > > > > ddlEndTimeHour.Items.FindByValue(timeEnd[0]).Selected =
true;
> > > > > > > > ddlEndTimeMinute.Items.FindByValue(timeEnd[1]).Selected =
true;
> > > > > > > >
> > > > > > > > The first two (the Start times) seem to work fine, but I get
an
> > > > error on
> > > > > > > the
> > > > > > > > EndTimeHour that says "A DropDownList cannot have multiple
items
> > > > > > > selected". I
> > > > > > > > dont understand why this is happening, it happens even if I
add
> > > > > > > > ddlEndTimeHour.SelectedItem = -1.
> > > > > > > >
> > > > > > > > Even odder than that... the StartTime for the test date is
> > 14:00,
> > > > and the
> > > > > > > > end time is 15:30. Obviously theStartTIme works, but if I
> > comment
> > > > out the
> > > > > > > 2
> > > > > > > > EndTime.Select lines, the EndTime DDLs shows 14:00 as well!
> > > > > > > >
> > > > > > > > It's as if ddlStartTimeHour and ddlEndTimeHour are
connected,
> > hence
> > > > I get
> > > > > > > > the error about no multiples. But that *cant* be the case...
can
> > > > it?!
> > > > > > > > ------------
> > > > > > > >
> > > > > > > > Having tried your idea of using SelectedIndex, what apepars
to
> > have
> > > > > > > happened
> > > > > > > > is that BOTH ddlStartTimeHour and ddlEndTimeHour have taken
the
> > > > value
> > > > > > > given
> > > > > > > > in the SelectedIndex statement...
> > > > > > > >
> > > > > > > > ddlEndTimeHour.SelectedIndex = 3;
> > > > > > > >
> > > > > > > > I don't understand why these 2 DropDownLists appear
connected
> > ?!!?
> > > > > > > >
> > > > > > > > Please help! This is driving me crazy!! :o(
> > > > > > > >
> > > > > > > >
> > > > > > > > Dan
> > > > > > > >
> > > > > > > >
> > > > > > > > "Eliyahu Goldin" wrote:
> > > > > > > >
> > > > > > > > > Dan,
> > > > > > > > >
> > > > > > > > > A ddl has always at least one item selected unless it is
> > empty.
> > > > You
> > > > > > > should
> > > > > > > > > set SelectedItem or SelectedIndex properties to change
> > selection.
> > > > > > > > >
> > > > > > > > > Eliyahu
> > > > > > > > >
> > > > > > > > > "dhnriverside" <dan@musoswire.com> wrote in message
> > > > > > > > > news:0679E5D3-7562-47F2-AD65-45BC079EB308@microsoft.com...
> > > > > > > > > > Hi guys
> > > > > > > > > >
> > > > > > > > > > Still having a problem with this dropdownlist.
> > > > > > > > > >
> > > > > > > > > > Basically, I've got 4. The first 2 work fine, then my
code
> > > > crashes on
> > > > > > > the
> > > > > > > > > > 3rd.
> > > > > > > > > >
> > > > > > > > > > ddlEndTimeHour.Items.FindByValue(endTime[0]).Selected =
> > true;
> > > > > > > > > >
> > > > > > > > > > Where endTime[0] is a string containing "15".
> > > > > > > > > >
> > > > > > > > > > I get the error "A DropDownList cannot have multiple
items
> > > > selected".
> > > > > > > I
> > > > > > > > > know
> > > > > > > > > > I'm not selecting any items anywhere else, although when
I
> > look
> > > > at the
> > > > > > > > > > generated HTML, the first item is marked
> > selected="selected".
> > > > I've
> > > > > > > tried
> > > > > > > > > > adding
> > > > > > > > > >
> > > > > > > > > > ddlEndTimeHour.Items[0].Selected = false;
> > > > > > > > > >
> > > > > > > > > > but that hasnt helped.
> > > > > > > > > >
> > > > > > > > > > What's going on?!
> > > > > > > > > >
> > > > > > > > > > Cheers
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Dan
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > >
> > > >
> > > >
> >
> >
> >
- Next message: Jeff B: "DESPERATE: FormsAuthentication Problem"
- Previous message: Jim Bancroft: "Re: Can I read code-behind info outside of asp.net?"
- In reply to: dhnriverside: "Re: DropDownList.FindByValue.Selected not working... help!"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|