Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.
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;
                }
            }
        }

    }
share|improve this question
    
what you actually want to as the way you are using switch statement looks really odd –  Muhammad Raja Mar 9 '13 at 17:14
    
@MuhammadRaja alright what should i use then ? –  Martin Mar 9 '13 at 17:15
    
What you are developing ? is it a webpart –  Muhammad Raja Mar 9 '13 at 17:26
    
@MuhammadRaja Yes –  Martin Mar 9 '13 at 17:29
    
which version of SharePoint you are developing it for –  Muhammad Raja Mar 9 '13 at 18:04

1 Answer 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

share|improve this answer
    
Alright , were could i find the jquery to add validations? –  Martin Mar 9 '13 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. –  Muhammad Raja Mar 9 '13 at 18:02
    
i have not worked with ajax but i have worked with Update panels "the tools that in VS" –  Martin Mar 9 '13 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 –  Martin Mar 9 '13 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" –  Martin Mar 9 '13 at 18:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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