Santosh Reddy

Santosh Reddy

  • 2.1k
  • 64
  • 15.7k

dropdownlist some code problems will come

Jun 24 2017 2:01 PM
My recouvrement is when will selected dropdown list that value is stored in my textbox
this is my code """"::::
 
code 
 
protected void Button1_Click(object sender, EventArgs e)
{
try
{
string db = ConfigurationManager.ConnectionStrings["DDDB"].ConnectionString;
SqlConnection con = new SqlConnection(db);
SqlCommand cmd = new SqlCommand("select id, name,village from gridview ", con);
con.Open();
SqlDataReader rr = cmd.ExecuteReader();
DropDown1.DataTextField = "name";
DropDown1.DataValueField = "id";
DropDown1.DataSource = rr;
DropDown1.DataBind();
con.Close();
Lbl.Text = "connected";
TextBox1.Text = DropDown1.SelectedValue;
}
catch (Exception ex)
{
Lbl.Text = ex.Message;
// Response.Write("<script>alert('" + ex + "')</script>");
}
}

Answers (5)