1
Solved to add from  dropdownlist,checkboxlist in a textbox multiple


    protected void ButtonAddDataBase_Click(object sender, EventArgs e)
    {
        string dropDownListValue =  DropDownListDataBase.SelectedItem.Value;
         resultValue += " ";

        TextBoxResultDataBaseSkills.Text += Environment.NewLine;
        TextBoxResultDataBaseSkills.Text += dropDownListValue + " - ";




        foreach (ListItem item in CheckBoxListDataBase.Items)
        {
            if (item.Text == "Beginner" && item.Selected)

                TextBoxResultDataBaseSkills.Text += item.Text; 
            else
            {

                if (item.Text == "Medium" && item.Selected)

                    TextBoxResultDataBaseSkills.Text += item.Text;
                else
                {

                    if (item.Text == "Expert" && item.Selected)

                        TextBoxResultDataBaseSkills.Text += item.Text;
                }
            }
        }

    }
6
  • what you actually want to as the way you are using switch statement looks really odd Commented Mar 9, 2013 at 17:14
  • @MuhammadRaja alright what should i use then ?
    – Batistuta
    Commented Mar 9, 2013 at 17:15
  • What you are developing ? is it a webpart Commented Mar 9, 2013 at 17:26
  • @MuhammadRaja Yes
    – Batistuta
    Commented Mar 9, 2013 at 17:29
  • which version of SharePoint you are developing it for Commented Mar 9, 2013 at 18:04

1 Answer 1

1

You should be doing something like this,

 protected void ButtonAddDataBase_Click(object sender, EventArgs e)
 {
     string textBoxValue = string.empty;

     //check if drop down value isn't null if it isn't then add it to text box
     if(!string.IsNullorEmpty(DropDownListDataBase.SelectedItem.Value.ToString()))
          textBoxValue  = DropDownListDataBase.SelectedItem.Value.ToString();


     //now check which checkbox is checked

     if(chkboxBeginner.Checked == true)
        textBoxValue  += ": " + chkboxBeginner.Text; // or maybe check .title

     else if(chkboxMedium.Checked == true)
        textBoxValue  += ": " + chkboxMedium.Text;

     else if(chkboxExpert.Checked == true)
        textBoxValue  += ": " + chkboxExpert.Text;

     //at end set text of your textbox
     TextBoxResultDataBaseSkills.Text = textBoxValue;
 }

I hand coded this code so there might be some exceptions you should be able to fix, you should also use jQuery to add validations so that only one checkbox is selected all the times and forcing user to select some value in dropdownlist.

you will have to set checkbox's ids and text values in asp.net markup if its happening in asp.net otherwise behind code in createchildcontrols methond.

You might have to add your controls within a Update Panel so that it won't post back and loose selected values.

Here's a question stating how to use update panel in webpart if you don't know already,

UpdatePanel with SharePoint 2010 web part

7
  • Alright , were could i find the jquery to add validations?
    – Batistuta
    Commented Mar 9, 2013 at 17:57
  • @Martin here's an example stackoverflow.com/questions/901712/… but did you ever worked with ajax or update panels as I think they will be easier for you to work with. Commented Mar 9, 2013 at 18:02
  • i have not worked with ajax but i have worked with Update panels "the tools that in VS"
    – Batistuta
    Commented Mar 9, 2013 at 18:08
  • @Muhammed Raja i have updated in the top the code that i have written i have putted all the code in a update panel
    – Batistuta
    Commented Mar 9, 2013 at 18:08
  • @Muhammed Raja i will also upload a image in the top, what my problem is now, i have putted al the code in a "Update Panel"
    – Batistuta
    Commented Mar 9, 2013 at 18:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.