protected void DDLNome_SelectedIndexChanged(object sender, EventArgs e) { string conexao = ConfigurationManager.ConnectionStrings["mydata"].ConnectionString; using (SqlConnection con = new SqlConnection(conexao)) { SqlCommand cmd = new SqlCommand($"Select * from TbClientes where Nome={DDLNome.SelectedItem.Value}", con); con.Open(); DDLNome.DataBind(); } }
protected void Page_Load(object sender, EventArgs e) { string conexao = ConfigurationManager.ConnectionStrings["mydata"].ConnectionString; if (!Page.IsPostBack) { using (SqlConnection con = new SqlConnection(conexao)) { SqlCommand cmd = new SqlCommand("Select Id,Nome from TbLoja", con); con.Open(); DDLNome.DataSource = cmd.ExecuteReader(); DDLNome.DataBind(); } } }