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;
}
}
}
}
-
what you actually want to as the way you are using switch statement looks really odd– Muhammad RajaCommented Mar 9, 2013 at 17:14
-
@MuhammadRaja alright what should i use then ?– BatistutaCommented Mar 9, 2013 at 17:15
-
What you are developing ? is it a webpart– Muhammad RajaCommented Mar 9, 2013 at 17:26
-
@MuhammadRaja Yes– BatistutaCommented Mar 9, 2013 at 17:29
-
which version of SharePoint you are developing it for– Muhammad RajaCommented Mar 9, 2013 at 18:04
1 Answer
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,
-
Alright , were could i find the jquery to add validations? 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" 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 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" Commented Mar 9, 2013 at 18:18