I have a asp.net web form which has textboxes and dropdown lists. I am populating the form from the database based on the primary key. The selected items of the dropdownlist are coming at the first position apart from its originial index. how to solve it?
protected void Button3_Click(object sender, EventArgs e)
{
con.Open();
string str;
str = "select * from (((service_master inner join serv_grp_mas on service_master.serv_grp_cd=serv_grp_mas.serv_grp_cd)inner join base_uom_mas on service_master.base_uom_cd= base_uom_mas.base_uom_cd)inner join tax_ind_mas on service_master.tax_ind=tax_ind_mas.tax_ind) where req_no='" + TextBox1.Text.Trim() + "' ";
OleDbCommand com = new OleDbCommand(str, con);
OleDbDataReader dr = com.ExecuteReader();
dr.Read();
if (dr.HasRows==true)
{
TextBox9.Text = dr["req_dt"].ToString();
Session["UserName"]=dr["req_by"].ToString();
TextBox3.Text= dr["ser_cd"].ToString();
TextBox4.Text=dr["Serv_desc"].ToString();
DropDownList3.SelectedItem.Text = dr["serv_grp_desc"].ToString();
DropDownList1.SelectedItem.Text = dr["base_uom_desc"].ToString();
TextBox5.Text=dr["sac_cd"].ToString();
TextBox6.Text=dr["ser_long_desc"].ToString();
DropDownList2.SelectedItem.Text = dr["tax_ind_desc"].ToString();
TextBox7.Text=dr["active_ind"].ToString();
TextBox8.Text=dr["del_ind"].ToString();
}
else
{
WebMsgBox.Show("The entry does not exist");
//TextBox1.Text = "";
TextBox9.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
DropDownList3.SelectedItem.Text = "";
DropDownList1.SelectedItem.Text = "";
TextBox5.Text = "";
TextBox6.Text = "";
DropDownList2.SelectedItem.Text = "";
TextBox7.Text = "";
TextBox8.Text = "";
}
dr.Close();
con.Close();
}