TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Kyle Oliver
NA
67
30.2k
How to clear drop down list?
Apr 2 2019 12:19 PM
Hi,
I have 5 drop down lists in my webpage which transfers the data to a database to be stored.
One of the drop down lists is as follows;
Male or Female
-- Select --
Male
Female
Once I press the "Add Employee" button the form must clear to be able to add another employee.
I am able to clear the text boxes on the form but the code I am using to clear the drop down list, clears all the list items in the drop down list and I am unable to use the list items in the dropdown list when I need to add another employee.
Drop down list code;
DropDownWorkforceProfileAddNewRace.Items.Clear();
This code clears all the list items in the drop down list, which is not what i need.
How can I clear the drop down selected value when the "Add Employee" button is pressed and still keep the list items in the drop down list?
My code for the webpage below;
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Data.SqlClient;
using
System.Data;
namespace
EmploymentEquity
{
public
partial
class
WorkforceProfileAddEmployee : System.Web.UI.Page
{
SqlConnection con =
new
SqlConnection(@
"Data Source=KYLELT\SQLEXPRESS;Initial Catalog=EmploymentEquity;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"
);
protected
void
Page_Load(object sender, EventArgs e)
{
}
protected
void
BtnAddNewEmployeeWorkforceProfile_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = System.Data.CommandType.Text;
cmd.CommandText =
"insert into WorkforceProfile values('"
+TxBxWorkforceProfileAddNewEmployeeCode.Text+
"','"
+TxBxWorkforceProfileAddNewEmployeeCode.Text+
"','"
+TxBxWorkforceProfileAddNewEmployeeName.Text+
"','"
+DropDownWorkforceProfileAddNewMaleFemale.SelectedValue+
"','"
+DropDownWorkforceProfileAddNewRace.SelectedValue+
"','"
+TxBxWorkforceProfileAddNewJobTitle.Text+
"','"
+DropDownWorkforceProfileAddNewOccLevel.SelectedValue+
"','"
+TxBxWorkforceProfileAddNewAnnualSalary.Text+
"','"
+DropDownWorkforceProfileAddNewForiegnNational.SelectedValue+
"','"
+DropDownWorkforceProfileAddNewDisabled.SelectedValue+
"')"
;
cmd.ExecuteNonQuery();
con.Close();
LblAddEmployeeSuccess.Text =
"Employee Added Successfully"
;
TxBxWorkforceProfileAddNewEmployeeCode.Text = String.Empty;
TxBxWorkforceProfileAddNewEmployeeName.Text = String.Empty;
DropDownWorkforceProfileAddNewMaleFemale.Items.Clear();
DropDownWorkforceProfileAddNewRace.Items.Clear();
TxBxWorkforceProfileAddNewJobTitle.Text = String.Empty;
DropDownWorkforceProfileAddNewOccLevel.Items.Clear();
TxBxWorkforceProfileAddNewAnnualSalary.Text = String.Empty;
DropDownWorkforceProfileAddNewForiegnNational.Items.Clear();
DropDownWorkforceProfileAddNewDisabled.Items.Clear();
Response.Redirect(
"WorkforceProfileAddEmployee.aspx"
);
}
protected
void
LinkButton1_Click(object sender, EventArgs e)
{
Response.Redirect(
"WorkforceProfile.aspx"
);
}
}
}
Reply
Answers (
3
)
HTTP Error 502.3 - Bad Gateway
40 forms or 1 form and 40 panels