PDA

View Full Version : ASP.NET VISUAL BASIC and checkbox


cece1980
09-08-2006, 10:01
ciao a tutti ho un problema con asp.net e visual basic

ho creato una tabella passando l'html da codice in questo modo per intenderci

........
Dim Row_Table As New HtmlTableRow
Dim Cell_FirstAlternateDescription As New HtmlTableCell
Dim Cell_FirstAlternateLink As New HtmlTableCell
Dim Cell_FirstAlternateMail As New HtmlTableCell

Cell_FirstAlternateDescription.InnerHtml = dr("TX_DESCRIZIONE")
Cell_FirstAlternateLink.InnerHtml = "<a onclick='javascript:window.open(""" & dr("TX_URLPDF") & """)'>&nbsp;&nbsp;&nbsp;<img src=""./images/PDF.gif"" runat=""server"">&nbsp;&nbsp;&nbsp;</a>"
Cell_FirstAlternateMail.InnerHtml = "<input type=""checkbox"" runat=""server"" value=""" & dr("C_BANCA") & "_" & dr("C_CAB") & """ id=""Chk_" & Indice_cfr & """>"

Row_Table.Cells.Add(Cell_FirstAlternateDescription)
Row_Table.Cells.Add(Cell_FirstAlternateLink)
Row_Table.Cells.Add(Cell_FirstAlternateMail)
ecc.....

il risultato finale è corretto e da codice html esce questa struttura

<tr class="datiTR2">
<td>hsdgfhsdgfh</td>
<td><a onclick='javascript:window.open(".sdfgsdfgsfdg")'>&nbsp;&nbsp;&nbsp;<img src="./images/PDF.gif" runat="server">&nbsp;&nbsp;&nbsp;</a></td>
<td><input type="checkbox" runat="server" value="32683" id="Chk_1"></td>
</tr>
<tr class="datiTR1">
<td>sdgfhsdfgh</td>
<td><a onclick='javascript:window.open(".fdsgsdsfdgdfsdfgsdf")'>&nbsp;&nbsp;&nbsp;<img src="./images/PDF.gif" runat="server">&nbsp;&nbsp;&nbsp;</a></td>
<td><input type="checkbox" runat="server" value="32683" id="Chk_2"></td>
</tr>

il problema sorge in questo momento =>
come devo fare per poter sapere se il checkbox chk_1 è stato selezionato o meno?
con questo comando riesco ad estrami il contenuto della cella

?Tbl_PDF.Rows.Item(0).Cells(2).InnerHtml
"<input type="checkbox" runat="server" value="32683_8329" id="Chk_1">"

ma se volessi avere il controllo del checkbox come devo fare?

Lupin3d
09-08-2006, 11:39
Ci sono 2 soluzioni secondo me:

1)
Dichiari a livello globale una variabile di tipo checkbox
Protected WithEvents chk As CheckBox

Nel tuo metodo o evento
[...]
Dim Cell_FirstAlternateMail As New HtmlTableCell

Dim chk As CheckBox
chk = New CheckBox
chk.AutoPostBack = True
'aggiungi tutte le proprietà che vuoi
AddHandler chk.CheckedChanged, AddressOf chk_CheckedChanged

[...]
Cell_FirstAlternateMail.Controls.Add(chk)

[...]
Row_Table.Cells.Add(Cell_FirstAlternateMail)

e poi ti crei l'evento associato al tuo controllo
Private Sub chk_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
' gestione evento
End Sub




Se vuoi lavorare usando la proprietà InnerHTML della cella dovresti aggiungere l'evento a runtime onClick="__doPostBack('idChk','')" questo ti fa fare il postback...poi dovrai gestire tu il resto...


ciao

cece1980
10-08-2006, 12:36
perfetto risolto il problema :=)
grazie mille per l'aiuto