将下拉列表和复选框列表中的值保存到数据库,并显示在列表框中

时间:2013-03-19 11:41:12

标签: sql-server

enter image description here

当我从dropdownlistdatabase和checkboxlistdatabase中选择时,我试图保存在“+”上,它保存到不同的表,列,Skill_name和Skill_Level,也在按钮“+”上我试图从数据库表中读取并显示在列表框中,但我没有在列表框中获得任何值。

protected void Buttonaddatabase_Click(object sender, EventArgs e)
    {

            string database;
            if (DropDownListDataBase.SelectedItem.Text == "- Select -")
            {
                LabelErrorDataBase.Visible = true;
                LabelErrorDataBase.Text = "Please select a value";
            }
            else if (DropDownListDataBase.SelectedItem.Text != "- Select -")
            {
                database = DropDownListDataBase.SelectedItem.Text;
            }
            else if (DropDownListDataBase.SelectedItem.Value == "Other" && TextBoxDataBaseOther.Text == "")
            {
                LabelErrorDataBase.Visible = true;
                LabelErrorDataBase.Text = "Please enter a value";
            }
            else if (DropDownListDataBase.SelectedItem.Value == "Other" && TextBoxDataBaseOther.Text != null)
            {
                foreach (var vItem in ListBoxDataBase.Items)
                {
                    if (ValueAlreadyInListDbTextBox(vItem))
                        return;
                }

                var mySkill = new TECHNICAL_SKILLS();
                mySkill.skill_name = DropDownListDataBase.SelectedItem.Value;
                mySkill.technical_skill_id = new Random().Next();

                var mySkillLevel = new TECHNICAL_SKILL_LEVEL();
                mySkillLevel.skill_level = CheckBoxListDataBase.SelectedItem.Value;
                mySkillLevel.technical_skill_level_id = new Random().Next();

                var empSkill = new EMPLOYEES_TECHNICAL_SKILLS
                {
                    TECHNICAL_SKILLS = mySkill,
                    TECHNICAL_SKILL_LEVEL = mySkillLevel,
                    employee_id = theEmp.employee_id
                };
                theEmp.EMPLOYEES_TECHNICAL_SKILLS.Add(empSkill);
                //databaslist.Add(DropDownListDataBase.SelectedItem.Value + " - " + CheckBoxListDataBase.SelectedItem.Value);
                databaslist.Add(mySkill.skill_name + " - " + mySkillLevel.skill_level);

                ListBoxDataBase.DataSource = databaslist;
                ListBoxDataBase.DataBind();

                //string s;
                //s = mySkill.skill_name + " - " + mySkillLevel.skill_level;
                //ListBoxDataBase.Items.Add(s);

                LabelErrorDataBase.Visible = false;
                TextBoxDataBaseOther.Text = String.Empty;
            }

            else
            {
                foreach (var vItem in ListBoxDataBase.Items)
                {
                    if (ValueAlreadyInListDb(vItem))
                        return;
                }

                var mySkill = new TECHNICAL_SKILLS();
                mySkill.skill_name = TextBoxDataBaseOther.Text;
                mySkill.technical_skill_id = new Random().Next();

                var mySkillLevel = new TECHNICAL_SKILL_LEVEL();
                mySkillLevel.skill_level = CheckBoxListDataBase.SelectedItem.Value;
                mySkillLevel.technical_skill_level_id = new Random().Next();

                var empSkill = new EMPLOYEES_TECHNICAL_SKILLS
                {
                    TECHNICAL_SKILLS = mySkill,
                    TECHNICAL_SKILL_LEVEL = mySkillLevel,
                    employee_id = theEmp.employee_id
                };
                theEmp.EMPLOYEES_TECHNICAL_SKILLS.Add(empSkill);

                string s;
                s = mySkill.skill_name + " - " + mySkillLevel.skill_level;
                ListBoxDataBase.Items.Add(s);

                LabelErrorDataBase.Visible = false;
            }

0 个答案:

没有答案