L
Larry
I've been reading some VB.net articles written for wndows forms allow one to
write a custom format routine to customize the formating of data in controls
at binding time to a dataset. I wanted to try applying this idea to a
datagrid. The examples in the docs look like this:
Private Sub DecimalToCurrencyString(sender As Object, cevent As _
ConvertEventArgs)
' The method converts only to string type. Test this using the
DesiredType.
If Not cevent.DesiredType Is GetType(String) Then
Exit Sub
End If
' Use the ToString method to format the value as currency ("c").
cevent.Value = CType(cevent.Value, Decimal).ToString("c")
End Sub
Private Sub CurrencyStringToDecimal(sender As Object, cevent As _
ConvertEventArgs)
' The method converts back to decimal type only.
If Not cevent.DesiredType Is GetType(Decimal) Then
Exit Sub
End If
' Converts the string back to decimal using the static ToDecimal method.
cevent.Value = Decimal.Parse(cevent.Value.ToString, _
NumberStyles.Currency, nothing)
End Sub
Private Sub BindControl
' Creates the binding first. The OrderAmount is a Decimal type.
Dim b As Binding = New Binding _
("Text", ds, "customers.custToOrders.OrderAmount")
' Add the delegates to the event
AddHandler b.Format, AddressOf DecimalToCurrencyString
AddHandler b.Parse, AddressOf CurrencyStringToDecimal
text1.DataBindings.Add(b)
End Sub
The first problem I ran into was trying to find a module to import that
would define the ConvertEventArgs type. So, my question is: does a format
event exists for databinding to a web control? and if so can it be done the
same way a windows form is done (as above) or is there a different way to do
the same thing? and lastly if this (the above example) should work how do I
get the references for the convertEventArgs included in my web application?
-Larry
write a custom format routine to customize the formating of data in controls
at binding time to a dataset. I wanted to try applying this idea to a
datagrid. The examples in the docs look like this:
Private Sub DecimalToCurrencyString(sender As Object, cevent As _
ConvertEventArgs)
' The method converts only to string type. Test this using the
DesiredType.
If Not cevent.DesiredType Is GetType(String) Then
Exit Sub
End If
' Use the ToString method to format the value as currency ("c").
cevent.Value = CType(cevent.Value, Decimal).ToString("c")
End Sub
Private Sub CurrencyStringToDecimal(sender As Object, cevent As _
ConvertEventArgs)
' The method converts back to decimal type only.
If Not cevent.DesiredType Is GetType(Decimal) Then
Exit Sub
End If
' Converts the string back to decimal using the static ToDecimal method.
cevent.Value = Decimal.Parse(cevent.Value.ToString, _
NumberStyles.Currency, nothing)
End Sub
Private Sub BindControl
' Creates the binding first. The OrderAmount is a Decimal type.
Dim b As Binding = New Binding _
("Text", ds, "customers.custToOrders.OrderAmount")
' Add the delegates to the event
AddHandler b.Format, AddressOf DecimalToCurrencyString
AddHandler b.Parse, AddressOf CurrencyStringToDecimal
text1.DataBindings.Add(b)
End Sub
The first problem I ran into was trying to find a module to import that
would define the ConvertEventArgs type. So, my question is: does a format
event exists for databinding to a web control? and if so can it be done the
same way a windows form is done (as above) or is there a different way to do
the same thing? and lastly if this (the above example) should work how do I
get the references for the convertEventArgs included in my web application?
-Larry