Ver Mensaje Individual
  #1 (permalink)  
Antiguo 15/07/2011, 09:04
Avatar de a83
a83
 
Fecha de Ingreso: noviembre-2005
Ubicación: Santiago de chile
Mensajes: 637
Antigüedad: 18 años, 5 meses
Puntos: 1
Pregunta como cargar dos combos box con asp.net c#

buen dia
tengo la siguiente cosnulta de llenado de dos conbo box
ej en uno me aparece el nombre y al selecionar el otro me aparece la direcion de su casa anbos datos estan en distintas tablas

esta es la clase en la cual llena un solo registro esta escho en C#

Código C#:
Ver original
  1. public DataTable cmd_responsable()
  2.         {
  3.             DataTable cmduser = new DataTable();
  4.             DataColumn column2 = new DataColumn();
  5.             column2.DataType = System.Type.GetType("System.Int32");
  6.             column2.AllowDBNull = true;
  7.             column2.Caption = "id_usuario";
  8.             column2.ColumnName = "id_usuario";
  9.             cmduser.Columns.Add(column2);
  10.             column2 = new DataColumn();
  11.             column2.DataType = System.Type.GetType("System.String");
  12.             column2.AllowDBNull = true;
  13.             column2.Caption = "Nombre";
  14.             column2.ColumnName = "Nombre";
  15.             cmduser.Columns.Add(column2);
  16.             string CadenaConexion;
  17.             CadenaConexion = WebConfigurationManager.AppSettings.Get("StoreSQLI");
  18.             String SQL;
  19.             SQL = "";
  20.             SQL = SQL + " select id_usuario,Nombre from tbl_usuarios WHERE id_estado = '1' ";//%
  21.             SqlConnection conn = new SqlConnection();
  22.             conn.ConnectionString = CadenaConexion;
  23.             SqlCommand cmd2 = null;
  24.             SqlDataReader reader = null;
  25.             DataRow rowAprobar;
  26.             try
  27.             {
  28.                 conn.Open();
  29.                 cmd2 = new SqlCommand(SQL, conn);
  30.                 reader = cmd2.ExecuteReader();
  31.                 while (reader.Read())
  32.                 {
  33.                     rowAprobar = cmduser.NewRow();
  34.                     rowAprobar["id_usuario"] = reader.GetInt32(0);
  35.                     rowAprobar["Nombre"] = reader.GetString(1);
  36.                     cmduser.Rows.Add(rowAprobar);
  37.                 }
  38.             }
  39.             catch (Exception ex)
  40.             {
  41.                 throw (ex);
  42.             }
  43.             finally
  44.             {
  45.                 if (reader != null && !reader.IsClosed)
  46.                     reader.Close();
  47.                 if (cmd2 != null)
  48.                     cmd2.Dispose();
  49.                 if (conn != null && conn.State != ConnectionState.Closed)
  50.                     conn.Close();
  51.             }
  52.  
  53.             return cmduser;
  54.         }



y este es donde rescupero el dato

Código ASP:
Ver original
  1. private void Seteacmd_responsable(System.Web.UI.WebControls.DropDownList midrp)
  2.     {
  3.         Classcmbllena cmd = new Classcmbllena();
  4.         midrp.Items.Clear();
  5.         midrp.DataValueField = "id_usuario";
  6.         midrp.DataTextField = "nombre";
  7.          try
  8.         {
  9.             midrp.DataSource = cmd.cmd_responsable();
  10.             midrp.DataBind();
  11.         }
  12.         catch (Exception ex)
  13.         {
  14.             this.lblErrorFocus.Text = ex.Message.ToString();
  15.         }
  16.         midrp.Items.Add(new ListItem("Selecionar", "Selecionar"));
  17.         midrp.SelectedIndex = midrp.Items.Count - 1;
  18.     }

como puedo cargar esto