Click here to Skip to main content
15,748,748 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to get the users to pick from a checkBoxList to pick popular options (Media, Flyer, School).
I want to store each on a newline like TxtMedia.Text += ChBMedia.Items[i].Text + "<br>";
or comma separated.

The other problem I am having is that the code does not work and unless the user only select other.

Finally, I don't want the the word "other" entered into the textbox when the user selects it.

thanks

What I have tried:

C#
protected void ChBMedia_SelectedIndexChanged1(object sender, EventArgs e)
         {
             TxtMedia.Text = "";
             for (int i = 0; i < ChBMedia.Items.Count; i++)
             {

                 if (ChBMedia.Items[i].Selected)
                 {

                     TxtMedia.Text += ChBMedia.Items[i].Text;

                 }
                 if (ChBMedia.SelectedItem.Value == "Other")
                 {
                     TxtMedia.Enabled = true;
                 }
                 else
                 {
                     TxtMedia.Enabled = false;
                 }
             }
Posted
Updated 5-Mar-16 13:57pm
v2

1 solution

Getting certain results from a CheckedListBox can be a bit 'unusual'.
It's not clear what you want when the 'Other' item is selected, but have a look at this:
C#
private void ChBMedia_MouseUp(object sender, MouseEventArgs e)
{
    TxtMedia.Clear();
    foreach (string item in ChBMedia.CheckedItems)
    {
        if (item != "Other")
        {
            TxtMedia.AppendText(item + Environment.NewLine);
        }
    }
}

It may also be a good idea to set: ChBMedia.CheckOnClick = true;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900