Binding CheckBox

lunedì 21 febbraio 2005 - 16.37

nothorius Profilo | Newbie

Salve a tutti.
Ho inserito in una tabella dei campi checkbox , ma ho riscontrato dei problemi :
1) quando ho cercato di effettuare l'aggiornamento del dataset tramite il dataadapter mi è stato restituito un errore perf quanto riguarda UPDATE e DELETE.
2) Se cerco di effettuare una di queste due operazioni mi viene restituito un errore.

Qualcuno può aiutarmi? Credo di dover modificare il codice per queste due operazioni ma come si fa?

Grazie in anticipo er l'aiuto.

Cteniza Profilo | Guru

Devi intercettare gli eventi Format e Parse esempio:
dBi = new Binding("Checked",this.dsTabe,"Numeratori.Tiponum");
dBi.Format += new ConvertEventHandler(FormatHandler);
dBi.Parse += new ConvertEventHandler(ParseHandler);

// ckAnno è un checkbox che nel database ha un valore boolean (bit)

this.ckAnno.DataBindings.Add(dBi)
...
private void FormatHandler(object sender, ConvertEventArgs e)
{
if (DBNull.Value == e.Value)
e.Value = false;
}

private void ParseHandler(object sender, ConvertEventArgs e)
{
if (e.Value == DBNull.Value)
e.Value = false;

nothorius Profilo | Newbie

grazie cteniza , ma hai l'esempio in vb.net

Cteniza Profilo | Guru

L'esempio tradotto in vbdotnettese :))

Private Sub BindControls()
dBi = New Binding("Checked", Me.dsTabe, "Numeratori.Tiponum")
AddHandler dBi.Format, AddressOf FormatHandler
AddHandler dBi.Parse, AddressOf ParseHandler
Me.ckAnno.DataBindings.Add(dBi)
End Sub
Private Sub FormatHandler(ByVal sender As Object, ByVal e As ConvertEventArgs)
If DBNull.Value = e.Value Then
e.Value = False
End If
End Sub

Private Sub ParseHandler(ByVal sender As Object, ByVal e As ConvertEventArgs)
If e.Value = DBNull.Value Then
e.Value = False
End If
End Sub

nothorius Profilo | Newbie

Grazie cteniza , provo e ti faccio sapere
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5