C sharp - ayuda con controles creados

 
Vista:

ayuda con controles creados

Publicado por Zero (3 intervenciones) el 12/05/2017 20:07:22
buenas espero me ayuden tengo el siguiente codigo

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
private void textBox_Leave(object sender, EventArgs e)
{
    DataTable dt = new DataTable();
 
    TextBox txtCodigoPostal = new TextBox();
 
    DAConexion cnx;
    if ("txtCodigoPostal" + "_" + (tabDireccion.TabPages.Count + 1) != "")
    {
        using (cnx = new DAConexion())
        {
            string cmdSQL = "select CP.id_CodigoPostal as Codigo_Postal, " +
            "L.Descripcion as Localidad," +
            "M.Descripcion as Municipio, " +
            "E.Descripcion as Estado," +
            "P.Descripcion as Pais " +
            "from c_CodigoPostal CP " +
            "inner join " +
            "c_Estado E on E.id_Estado = CP.id_Estado " +
            "inner join " +
            "c_Municipio M on M.id_Municipio = CP.id_Municipio and M.id_Estado = CP.id_Estado " +
            "left join " +
            "c_Localidad L on L.id_Estado = CP.id_Estado and L.id_Localidad = CP.id_Localidad " +
            "inner join " +
            "c_Pais P on P.id_Pais = E.id_Pais " +
            "where CP.id_CodigoPostal = '" + ((TextBox)txtCodigoPostal.Controls[("txtCodigoPostal" + "_" + (tabDireccion.TabPages.Count + 1))]).Text + "'";
 
            cnx.DbCommand.CommandText = cmdSQL;
            cnx.DbCommand.ExecuteNonQuery();
 
            dt = cnx.CrearDataTable(cmdSQL);
 
            try
            {
                DataRow dr = dt.Rows[0];
 
                if (dt.Rows.Count > 0)
                {
                    if (dr["Localidad"].ToString() == "")
                    {
                        //"txtCodigoPostal" + "_" + (tabDireccion.TabPages.Count + 1);
                    }
                    else
                    {
                        txtLocalidad.Text = dr["Localidad"].ToString();
                    }
                    txtMunicipio.Text = dr["Municipio"].ToString();
                    txtEstado.Text = dr["Estado"].ToString();
                    txtPais.Text = dr["Pais"].ToString();
 
                    string cmdSQL2 = "select id_Colonia, Descripcion from c_Colonia where id_CodigoPostal ='" + txtCodigoPostal.Text + "'";
                    UIUtileriasUIL.InicializarComboBox(cnx, cbbColonia, false, DBNull.Value, true, "-1", cmdSQL2);
                }
                else
                {
                    //ucMessageBox.ShowMessage("El codigo postal no es valido");
                    txtLocalidad.Text = "";
                    txtMunicipio.Text = "";
                    txtEstado.Text = "";
                    txtPais.Text = "";
                    return;
                }
            }
            catch (Exception ex)
            {
                //ucMessageBox.ShowMessage(ex.Message);
            }
        }
    }
    else
    {
        //ucMessageBox.ShowMessage("Debe capturar un codigo postal valido");
        return;
    }

intento crear un tab cuando agrego una direccion
entonces todos los controles tienen un _ seguido del numero del tab todo esta bn cuando accedo al evento del leave

marca error a la hora de acceder al control del txtcodigopostal_2 cual es la forma de acceder a esos tipos de controles creados???


saludos espero me puedan ayudar
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder