Ver Mensaje Individual
  #2 (permalink)  
Antiguo 23/11/2012, 08:40
Avatar de Aquaventus
Aquaventus
 
Fecha de Ingreso: junio-2010
Ubicación: Lima-Peru , En el alba de la naturaleza
Mensajes: 2.105
Antigüedad: 13 años, 10 meses
Puntos: 267
Respuesta: Broblemas dropdownlist anidados.

Hola Darsk recuerda preguntar por el estado de la conexión para que no hagas el cierre de conexión forzado, podrías hacer lo siguiente :
Código C:
Ver original
  1. protected void cbRegion_SelectedIndexChanged(object sender, EventArgs e)
  2.     {
  3.         if(cboRegion.SelectedIndex != -1)
  4.         {
  5.         string id_region = cbRegion.SelectedValue.ToString();
  6.         SqlCommand cmd = new SqlCommand("select * from ciudad where id_region_fk = '" + id_region + "'", conn);
  7.         SqlDataAdapter da = new SqlDataAdapter(cmd.CommandText, conn);
  8.         DataSet ds = new DataSet();
  9.         da.Fill(ds);
  10.         this.cbCiudad.DataSource = ds;
  11.         this.cbCiudad.DataValueField = "id_ciudad";
  12.         this.cbCiudad.DataTextField = "nombre";
  13.         this.cbCiudad.DataBind();
  14.         if (cbCiudad.Items.Count != 0)
  15.         {
  16.             string id_ciudad = cbCiudad.SelectedValue.ToString();
  17.             cargarComunas(id_ciudad);
  18.             if(conn.Status == ConnectionState.Open){
  19.                 conn.Close();
  20.             }        
  21.         }
  22.         else
  23.         {
  24.             cbCiudad.Items.Clear();
  25.         }
  26.         }
  27.     }

Código C:
Ver original
  1. public void cargarCiudades(string id_region)
  2.     {
  3.         if(cbCiudad.SelectedIndex != -1)
  4.         {        
  5.         SqlCommand cmd = new SqlCommand("select * from ciudad where id_region_fk = '"+id_region+"'",conn);
  6.         SqlDataAdapter da = new SqlDataAdapter(cmd.CommandText, conn);
  7.         DataSet ds = new DataSet();
  8.         da.Fill(ds);
  9.         this.cbCiudad.DataSource = ds;
  10.         this.cbCiudad.DataValueField = "id_ciudad";
  11.         this.cbCiudad.DataTextField = "nombre";
  12.         this.cbCiudad.DataBind();
  13.         if (cbCiudad.Items.Count != 0)
  14.         {
  15.             string id_ciudad = cbCiudad.SelectedValue.ToString();
  16.             cargarComunas(id_ciudad);
  17.             if(conn.Status == ConnectionState.Open){
  18.                 conn.Close();
  19.             }  
  20.              
  21.         }
  22.         else
  23.         {
  24.             cbCiudad.Items.Clear();
  25.         }
  26.         }
  27.     }

Código C:
Ver original
  1. public void cargarComunas(String id_ciudad)
  2.     {
  3.         SqlCommand cmd = new SqlCommand("select * from comunas where id_ciudad_fk ='"+id_ciudad+"'", conn);
  4.         SqlDataAdapter da = new SqlDataAdapter(cmd.CommandText, conn);
  5.         DataSet ds = new DataSet();
  6.         da.Fill(ds);
  7.         this.cbComuna.DataSource = ds;
  8.         this.cbComuna.DataValueField = "id_comuna";
  9.         this.cbComuna.DataTextField = "nombre";
  10.         this.cbComuna.DataBind();
  11.         if(cbComuna.Items.Count !=0)
  12.         {
  13.             string id_comuna = Convert.ToString(cbComuna.SelectedValue);
  14.        
  15.         }
  16.         else
  17.         {
  18.             cbComuna.Items.Clear();
  19.         }
  20.        
  21.     }
Prueba y nos comentas. Saludos!.
__________________
Internet es tener todo el conocimiento global a tu disposición.
Desarrollo de Software - Ejemplos .Net