i have tried to to load the data to text box, while selecting the drop down list, i was created a class for retrieval and called it in drop down list selected index changed. But i cant get the answer what i want. If i have called the class in Button click event it has worked properly. So please correct me. What i made a mistake. This is what my code:
public void so()
{
con.Open();
string s2;
s2 = "select Source from tbl_component where Componetcode='" + Mcodeddl.SelectedItem.Text + "'";
SqlCommand c2 = new SqlCommand(s2, con);
SqlDataReader d2;
d2 = c2.ExecuteReader();
while (d2.Read())
{
TextBox1.Text = d2["Source"].ToString().Trim();
}
d2.Close();
con.Close();
}
//i have called the so class here
protected void Mcodeddl_SelectedIndexChanged(object sender, EventArgs e)
{
so();
}