I'm using following DropDownList event to select an employee from MS SQL Server 2005 and showing the employee's information on TextBox.
protected void employeeDropDownList_SelectedIndexChanged(object sender,
EventArgs e)
{
EmployeeDAL employeeDAL = new EmployeeDAL();
DataTable dataTable = employeeDAL.GetEmployeeData();
for (int i = 1; i <= dataTable.Rows.Count; i++)
{
if (Convert.ToInt32(employeeDropDownList.SelectedValue) == i)
{
nameTextBox.Text = dataTable.Rows[i-1]["employee_Name"].ToString();
useNameTextBox.Text=dataTable.Rows[i-1]["employee_UserName"].ToString();
addressTextBox.Text=dataTable.Rows[i-1]["employee_Address"].ToString();
break;
}
}
}
Then I'm using the following Button event to update Employee information.
protected void employeeUpdateButton_Click(object sender, EventArgs e)
{
EmployeeDAL employeeDAL = new EmployeeDAL();
EmployeeDAO employeeDAO = new EmployeeDAO
{
EmployeeID = Convert
.ToInt32(employeeDropDownList.SelectedValue),
Name = nameTextBox.Text,
Username = useNameTextBox.Text,
Address = addressTextBox.Text,
};
employeeDAL.UpdateEmployee(employeeDAO);
}
But the problem is... values of the TextBoxes are not changing. I mean TextBoxes are keeping previous values those were assigned in employeeDropDownList_SelectedIndexChanged event. But why? What should I do now?