Foros del Web

Foros del Web (http://www.forosdelweb.com/)
-   ASPX (.net) (http://www.forosdelweb.com/f78/)
-   -   Recorrer fila de tabla HTML (http://www.forosdelweb.com/f78/recorrer-fila-tabla-html-588492/)

BACH 21/05/2008 07:51

Recorrer fila de tabla HTML
 
Buen dia...
Tengo una tabla html la cual voy llenando dinamicamente. Tiene 4 columnas: nombre, codigo, materia (estos 3 son textbox) y upd (en la q hay un checkbox x cada fila). Lo q quiero hacer es q si el checkbox esta chequeado los texbox de esa fila se activen para poder actualizar los datos, pero no se como recorrer la tabla para verificar el estado del checkbox...espero q me puedan ayudar

Con este metodo creo la tabla
public Table tableHTML()
{
Table tabla_retorno = new Table();
tabla_retorno.BorderWidth = 1;
TableHeaderRow Hrow = new TableHeaderRow();
TableHeaderCell hNomTit = new TableHeaderCell();
TableHeaderCell hCodTit = new TableHeaderCell();
TableHeaderCell hCarTit = new TableHeaderCell();

hNomTit.Text = "NOMBRE";
hCodTit.Text = "CÓDIGO";
hMatTit.Text = "MATERIA";

Hrow.Cells.Add(hNomTit);
Hrow.Cells.Add(hCodTit);
Hrow.Cells.Add(hCarTit);

tabla_retorno.Rows.Add(Hrow);

foreach (clsEstudiante est in this.estudiantes)
{
TableRow row = new TableRow();


TableCell cNombres = new TableCell();
TableCell cCodigo = new TableCell();
TableCell cMateria = new TableCell();
TableCell chkUpdate = new TableCell();

TextBox tx1 = new TextBox();
TextBox tx2 = new TextBox();
TextBox tx3 = new TextBox();
CheckBox chkActu = new CheckBox();

tx1.Enabled = false;
tx2.Enabled = false;
tx3.Enabled = false;

cNombres.Text = est.nombreProp;
cCodigo.Text = est.codigoProp;
cMateria.Text = est.materiaProp;

tx1.Text = cNombres.Text;
tx2.Text = cCodigo.Text;
tx3.Text = cMateria.Text;

cNombres.Controls.Add(tx1);
cCodigo.Controls.Add(tx2);
cMateria.Controls.Add(tx3);
chkUpdate.Controls.Add(chkActu);


row.Cells.Add(cNombres);
row.Cells.Add(cCodigo);
row.Cells.Add(cMateria);
row.Cells.Add(chkUpdate);

tabla_retorno.Rows.Add(row);

}
return (tabla_retorno);

}

Javier Santamaria 22/05/2008 04:06

Respuesta: Recorrer fila de tabla HTML
 
Hola,

Tienes que dar un identificador a esos controles para poderlos manejar (habilitarlos, deshabilitarlos...)

Recorrer la tabla es con un bucle for o while y preguntar si ese checkbox esta habilitado. Para perguntar esto necesitas el identificador mencionado anteriormente

Saludos

BACH 22/05/2008 06:30

Respuesta: Recorrer fila de tabla HTML
 
Gracias x responder Javier...
Yo hago el sgte ciclo
for (i = 1; i <= tablaHtml.Rows.Count; i++)
{
if(tablaHtml.Rows[i].Cells[3].???)
{

}
}

pero como hago lo del identificador para saber en cual estoy?
La idea q tenia con el if era preguntar si el checkbox esta activado, pero no se que poner en vez de los ??? para acceder al control. Lei que se debia usar un manejador de eventos, algo como
chkActu.CheckedChanged += new EventHandler
pero no se realmente como....

Javier Santamaria 23/05/2008 03:09

Respuesta: Recorrer fila de tabla HTML
 
Hola,

Mira yo los creo asi los controles dinamicos:

Dim outward As New TableHeaderCell
Dim cboutward As New CheckBox
cboutward.ID = "CBOutwardtbl" & table.Rows.Count.ToString 'Aqui le doy el identificador que te comentaba, recuerda darle un indice para saber la fila donde esta
cboutward.TabIndex = tabindex + 7 'Aqui le asigno el tabindex, pero esto no es necesario si no quieres
outward.Controls.Add(cboutward)
emptyrow.Cells.Add(outward)

Luego para acceder a ese control la hago asi:

For i = 0 To TblPassengers.Rows.Count - 1
r = TblPassengers.Rows.Item(i)
For Each c In r.Cells
For Each con In c.Controls
Dim name As String
name = con.ID
Select Case name
Case "CBOutwardtbl" & i.ToString
Dim cb As New CheckBox
cb = con.FindControl("CBOutwardtbl" & i.ToString)
'Ahora ese checkbox creado anteriormente lo tienes en cb
...

Espero que te sirva

Saludos

RootK 23/05/2008 11:11

Respuesta: Recorrer fila de tabla HTML
 
podría quedar de ésta forma:

Código:

public Table tableHTML()
    {
        Table tabla_retorno = new Table();
        tabla_retorno.BorderWidth = 1;
       
        TableHeaderRow headerRow = new TableHeaderRow();

        TableHeaderCell headerCell = new TableHeaderCell();
        headerCell.Text = "NOMBRE";
        headerRow.Cells.Add(headerCell);

        headerCell = new TableHeaderCell();
        headerCell.Text = "CÓDIGO";
        headerRow.Cells.Add(headerCell);

        headerCell = new TableHeaderCell();
        headerCell.Text = "MATERIA";
        headerRow.Cells.Add(headerCell);

        tabla_retorno.Rows.Add(headerRow);

        foreach (clsEstudiante est in this.estudiantes)
        {
            TableRow row = new TableRow();

            TextBox txt = new TextBox();
            txt.Enabled = false;
            txt.Text = est.nombreProp;
            TableCell tc = new TableCell();
            tc.Controls.Add(txt);
            row.Cells.Add(tc);

            txt = new TextBox();
            txt.Enabled = false;
            txt.Text = est.codigoProp;
            tc = new TableCell();
            tc.Controls.Add(txt);
            row.Cells.Add(tc);

            txt = new TextBox();
            txt.Enabled = false;
            txt.Text = est.materiaProp;
            tc = new TableCell();
            tc.Controls.Add(txt);
            row.Cells.Add(tc);
           
            CheckBox chkActu = new CheckBox();
            chkActu.ID = "chkActu_" + Guid.NewGuid().ToString();
            tc = new TableCell();
            tc.Controls.Add(chkActu);
            row.Cells.Add(tc);

            tabla_retorno.Rows.Add(row);
 
        }
       
        return tabla_retorno;

    }

Y para encontrar tu checkbox

Código:

for (int i = 1; i < tbl.Rows.Count; i++)
        {
            CheckBox chkActu = (CheckBox)tbl.Rows[i].Cells[3].Controls[0];
            //tu código para validar el checkbox
        }

Tomando en cuenta que se encuentra en la 3ra celda tu checkbox

Salu2


La zona horaria es GMT -6. Ahora son las 01:17.

Desarrollado por vBulletin® Versión 3.8.7
Derechos de Autor ©2000 - 2026, Jelsoft Enterprises Ltd.