CheckboxList problem

  • Thread starter Thread starter Jeppe Jespersen
  • Start date Start date
Jeppe:
First, I'd like to thank you for posting the video,obviously took away any
ambiguity of what your problem was. Adds a bit of spice to the day to day
helping ;)

That said, I'm not sure what to tell you other than, that's just how it
works :(

You are binding your 2nd result to the SelectedValue of your checkboxlist
control. SelectedValue returns only the first value selected - that's it's
documented behaviour and that's what you are seeing.

What you can do is create your own server control which inherits from
CheckBoxList, and in it add a single property, AllSelectedValues which would
do what you want, perhaps something like:

public class EnhancedCheckboxList : CheckBoxList
{
public string AllSelectedValues
{
get
{
base.EnsureChildControls();
StringBuilder sb = new StringBuilder();
foreach(ListItem item in base.Items)
{
if (item.Selected)
{
sb.Append(item.Value);
sb.Append(",");
}
}
//trim trailing comma here, too lazy to do it myself
return sb.ToString();
}
}
}

This would return a comma-sepearted list, which you might be able to use in
an IN statement, not sure.

I'm just going off the top of my head, and this might not work at all, but
thought it might provide some help.

As a solution, you could avoid using the SqlDataSource, which promotes bad
design anyways :)

Karl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top