Search This Blog

Sunday, January 17, 2010

Databinding to single value: Code :

Partial Class _Default
Inherits System.Web.UI.Page
ReadOnly Property OrderDate() As String
Get
Dim CurrentDate As Date
CurrentDate = Date.Now
Return CurrentDate
End Get
End Property

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
OrderDateBox.DataBind()
End If
End Sub

Protected Sub SubmitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SubmitButton.Click
MessageLabel.DataBind()
MessageLabel.Visible = True
End Sub
'method is created to illustrate binding control to method
Function CalculateDiscount() As Integer
If Val(QuantityBox.Text) >= 20 And Val(QuantityBox.Text) <= 50 Then Return 20 ElseIf Val(QuantityBox.Text) > 50 Then
Return 30
Else
Return 0
End If
End Function

Protected Sub DiscountButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles DiscountButton.Click
DiscountLabel.DataBind()
CalculateDiscount()
End Sub

Protected Sub AmtButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles AmtButton.Click
AmountBox.DataBind()
End Sub
'(val(QuantityBox.text)* val(PriceBox.Text))-((val(DiscountLabel.Text)/100)* (val(QuantityBox.Text)*val(PriceBox.Text)))
End Class

No comments:

Post a Comment