On Feb 27, 1:08 pm, G=F6ran Andersson <g...@guffa.com> wrote:
> r...@rediffmail.com wrote:
> > 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:
>
> > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> > If (CType(ea.Item.Cells(4).Controls(1), TextBox).Text =3D "") Then
> > lblMessage.Text =3D "Quantity cannot be blank"
> > Else
> > If Not (IsNumeric(CType(ea.Item.Cells(4).Controls(1),
> > TextBox).Text)) Then
> > lblMessage.Text =3D "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 <=3D 0)
> > Then
> > lblMessage.Text =3D "Quantity must be greater than zero"
> > Else
> > Dim iQty As Integer
>
> > iQty =3D CInt(CType(ea.Item.Cells(4).Controls(1),
> > TextBox).Text)
> > .........................
> > .........................
> > .........................
> > End If
> > End If
> > End If
> > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
>
> > 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?
>
> You are rounding the value when you convert it into an integer. When you
> have determined that it's a number, convert into a Double, then do the
> range check on the Double.
>
> --
> G=F6ran Andersson
> _____
http://www.guffa.com- Hide quoted text -
>
> - Show quoted text -