471,122 Members | 2,335 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,122 software developers and data experts.

getting the value of a selected/unselected item in a checkboxlist

I am having a bit of a problem getting the current value of the checkbox
list.

I have tried using the selected value as I thought that would give me the
current value of the check box but it appears to be giving me the first
value that is selected all the time.

I have also tried to use the selectedItem property but that does the same as
I would expect becuase the property says it get the item with the lowest
value.

How can I get the current value of a checkboxlist?

TIA,
Brett
Jun 6 '07 #1
4 4215
On Wed, 06 Jun 2007 09:33:56 -0700, Brett Wesoloski <br*********@pai.com>
wrote:
I am having a bit of a problem getting the current value of the checkbox
list.
Can you define "current value"? If multiple items in the list can be
selected (checked, in this case), what is the "current value", given that
there are multiple items with values that have been selected?
I have tried using the selected value as I thought that would give me the
current value of the check box but it appears to be giving me the first
value that is selected all the time.
Yup. The term "current value" isn't defined yet, but I am not surprised
that you get the first selected item in the list when you get the
SelectedValue.
I have also tried to use the selectedItem property but that does the
same as
I would expect becuase the property says it get the item with the lowest
value.
Actually, it says "lowest index". Note that SelectedValue and
SelectedIndex work together. In particular, all that SelectedValue does
is return the Value property of the ListItem that is at SelectedIndex.
How can I get the current value of a checkboxlist?
It's not possible to answer that question until you explain what you mean
by "current value".

Pete
Jun 6 '07 #2
What I mean by current value is the check box you just checked.

For instance I have these check boxes.

a
b
c
d
e
f
g
Now I select the b check box. The current value is b. Then I go and select
the f check box. The current value is f as that was the next check box to
be selected.

Does that help?

TIA,
Brett

"Peter Duniho" <Np*********@nnowslpianmk.comwrote in message
news:op***************@petes-computer.local...
On Wed, 06 Jun 2007 09:33:56 -0700, Brett Wesoloski <br*********@pai.com>
wrote:
>I am having a bit of a problem getting the current value of the checkbox
list.

Can you define "current value"? If multiple items in the list can be
selected (checked, in this case), what is the "current value", given that
there are multiple items with values that have been selected?
>I have tried using the selected value as I thought that would give me the
current value of the check box but it appears to be giving me the first
value that is selected all the time.

Yup. The term "current value" isn't defined yet, but I am not surprised
that you get the first selected item in the list when you get the
SelectedValue.
>I have also tried to use the selectedItem property but that does the
same as
I would expect becuase the property says it get the item with the lowest
value.

Actually, it says "lowest index". Note that SelectedValue and
SelectedIndex work together. In particular, all that SelectedValue does
is return the Value property of the ListItem that is at SelectedIndex.
>How can I get the current value of a checkboxlist?

It's not possible to answer that question until you explain what you mean
by "current value".

Pete

Jun 6 '07 #3
On Wed, 06 Jun 2007 12:08:43 -0700, Brett Wesoloski <br*********@pai.com>
wrote:
What I mean by current value is the check box you just checked.
Okay. I'll suggest that's not a broadly used concept of "current value".
:)
[...]
Now I select the b check box. The current value is b. Then I go and
select
the f check box. The current value is f as that was the next check box
to
be selected.

Does that help?
Sure. What you actually want is the checkbox that actually has *focus*.
That's entirely different from the one(s) that is(are) selected.

Not having done the ASP/web .NET stuff, I'm not sure how you can actually
get that. My first thought would be that you could enumerate the ListItem
instances in the CheckboxList and check to see which one (if any) has the
focus. But I don't see any immediate way to do that in the ListItem class.

If it's possible, it probably has something to do with the larger browser
container somehow, since in the context of a web page, focus can actually
leave the web page, and so I would not expect it to necessarily be tracked
by the web page itself. But I admit, never had to do any of the web UI
stuff, so I don't know for sure one way or the other.

As a last resort, it may be that you can track when any of the items in
the CheckboxList change, and by doing so, keep track of the one that most
recently changed. Then consider that the one with "focus" any time you
care about that.

Hopefully knowing that you are actually asking about "focus" rather than
"selection", that may help you in your search through the documentation.

Pete
Jun 7 '07 #4
Brett, did you find a solution? I'm also attempting the same thing. I have a CheckBoxList and I want to know which box was selected/unselected on SelectedIndexChanged. I'm considering rewriting the checkboxes to use a Repeater and have individual checkboxes rather than a CheckBoxList. If I did that, I'd know exactly which one had changed. Thoughts? Thanks! -Eric

EggHeadCafe.com - .NET Developer Portal of Choice
http://www.eggheadcafe.com
Jun 13 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Jozef Jarosciak | last post: by
reply views Thread by Francois Verbeeck | last post: by
1 post views Thread by rbscheer | last post: by
2 posts views Thread by billyb | last post: by
4 posts views Thread by planetthoughtful | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.