
uso de dropdownlist anidados
Publicado por yalefon (1 intervención) el 24/11/2012 19:23:41
hola foro, tengo el siguiente problemita, tal ves me pueden ayudar..tengo dos dropdownlist1 lo cargo en pagina padre y dropdownlist2 lo cargo en la pagina hijo por medio de un boton popup..
lo q quiero es realizar lo siguiente.al carga el dropdownlist1, cuando el usuario seleccione un dato=id, q me ejecute en el SelectedIndexChanged una consulta para asi llemar el dropdownlist2 ...
tengo el siguiente codigo para q se llene el dropdownlist2..
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (Convert.ToInt32(DropDownList1.SelectedValue) == 1)
{
using (SqlConnection cnx = new SqlConnection(cx))
{
cnx.Open();
try
{
string sql = "select Serie from Correlativos where Id_tipo='DropDownList1.SelectedValue'";
SqlCommand cmd = new SqlCommand(sql, cnx);
cant2 = Convert.ToString(cmd.ExecuteScalar());
}
catch (SqlException) { throw; }
finally
{
if (cnx.State == ConnectionState.Open) cnx.Close();
if (cnx.State == ConnectionState.Broken) cnx.Close();
}
}
}
Session["Datos"] = Convert.ToString(cant2); //este el dato q se tiene q cargar en el dropdownlist 2
}
espero su ayuda...
saludos..
lo q quiero es realizar lo siguiente.al carga el dropdownlist1, cuando el usuario seleccione un dato=id, q me ejecute en el SelectedIndexChanged una consulta para asi llemar el dropdownlist2 ...
tengo el siguiente codigo para q se llene el dropdownlist2..
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (Convert.ToInt32(DropDownList1.SelectedValue) == 1)
{
using (SqlConnection cnx = new SqlConnection(cx))
{
cnx.Open();
try
{
string sql = "select Serie from Correlativos where Id_tipo='DropDownList1.SelectedValue'";
SqlCommand cmd = new SqlCommand(sql, cnx);
cant2 = Convert.ToString(cmd.ExecuteScalar());
}
catch (SqlException) { throw; }
finally
{
if (cnx.State == ConnectionState.Open) cnx.Close();
if (cnx.State == ConnectionState.Broken) cnx.Close();
}
}
}
Session["Datos"] = Convert.ToString(cant2); //este el dato q se tiene q cargar en el dropdownlist 2
}
espero su ayuda...
saludos..
Valora esta pregunta


0