R
rn5a
A Web Form has a TextBox within a DataGrid wherein users are expected
to enter only whole numbers. It should be validated so that the
TextBox doesn't remain blank or any non-numeric data is entered in the
TextBox. If the TextBox doesn't get validated, I want to display
messages to the user which should be as precise as possible for the
user to easily identify where he erred. This is how I did it:
==========================================
If (CType(ea.Item.Cells(4).Controls(1), TextBox).Text = "") Then
lblMessage.Text = "Quantity cannot be blank"
Else
If Not (IsNumeric(CType(ea.Item.Cells(4).Controls(1),
TextBox).Text)) Then
lblMessage.Text = "Quantity must be a number"
Else
Response.Write(CType(ea.Item.Cells(4).Controls(1),
TextBox).Text)
If (CType(ea.Item.Cells(4).Controls(1), TextBox).Text <= 0)
Then
lblMessage.Text = "Quantity must be greater than zero"
Else
Dim iQty As Integer
iQty = CInt(CType(ea.Item.Cells(4).Controls(1),
TextBox).Text)
.........................
.........................
.........................
End If
End If
End If
==========================================
The first 2 If conditions work correctly but the 3rd & the last one
doesn't. If I enter 0.8 in the TextBox, then it automatically gets
rounded to 1 & hence doesn't display the message "Quantity must be
greater than zero" though the Response.Write statement just before the
last If condition outputs the TextBox value as 0.8. Same is the case
if I enter 0.2 in the TextBox; it automatically gets rounded to 0.
How do I prevent the TextBox value from getting rounded when the Form
is submitted?
to enter only whole numbers. It should be validated so that the
TextBox doesn't remain blank or any non-numeric data is entered in the
TextBox. If the TextBox doesn't get validated, I want to display
messages to the user which should be as precise as possible for the
user to easily identify where he erred. This is how I did it:
==========================================
If (CType(ea.Item.Cells(4).Controls(1), TextBox).Text = "") Then
lblMessage.Text = "Quantity cannot be blank"
Else
If Not (IsNumeric(CType(ea.Item.Cells(4).Controls(1),
TextBox).Text)) Then
lblMessage.Text = "Quantity must be a number"
Else
Response.Write(CType(ea.Item.Cells(4).Controls(1),
TextBox).Text)
If (CType(ea.Item.Cells(4).Controls(1), TextBox).Text <= 0)
Then
lblMessage.Text = "Quantity must be greater than zero"
Else
Dim iQty As Integer
iQty = CInt(CType(ea.Item.Cells(4).Controls(1),
TextBox).Text)
.........................
.........................
.........................
End If
End If
End If
==========================================
The first 2 If conditions work correctly but the 3rd & the last one
doesn't. If I enter 0.8 in the TextBox, then it automatically gets
rounded to 1 & hence doesn't display the message "Quantity must be
greater than zero" though the Response.Write statement just before the
last If condition outputs the TextBox value as 0.8. Same is the case
if I enter 0.2 in the TextBox; it automatically gets rounded to 0.
How do I prevent the TextBox value from getting rounded when the Form
is submitted?