I was create a Employee registration page with dropdown list.Its used for selecting priority for each user. suppose i want to edit some user detail in this time am using the below code to select the dropdown list. It returns repeat value with out first index. That means a user have 3rd priority means it select third priority with out having 1st priority.
foreach (DataRow dr in DS.Rows)
{
txtemail.Enabled = false;
pan_addEdit.Visible = true;
this.btnSave.Text = "Update";
lbluserid.Text = Convert.ToString(dr["fdluserId"]);
txtuername.Text = Convert.ToString(dr["flduser"]);
txtPass.Text = Convert.ToString(dr["fldpass"]);
txtemail.Text = Convert.ToString(dr["fldemail"]);
ddlstatus.SelectedValue = Convert.ToString(dr["fldstatus"]);
ddlusergroup.SelectedValue = Convert.ToString(dr["fldgroupId"]);
ddldept.SelectedValue = Convert.ToString(dr["flddept"]);
ddlperiority.SelectedValue = Convert.ToString(dr["fldperiority"]);
}
dropdown show the below value after binding
1st priority
2nd priority
3rd priority
dropdown show the below value after binding
3rd priority
2nd priority
3rd priority
please help me to fix this error..
You can use the FindByValue method to search the DropDownList for an Item with a Value matching the parameter.
Alternatively you can use the FindByText method to search the DropDownList for an Item with Text matching the parameter.
Before using the FindByValue method, don’t forget to reset the DropDownList so that no items are selected by using the ClearSelection() method. It clears out the list selection and sets the Selected property of all items to false. Otherwise you will get the following exception.