Validation for DataGrid

M

Matthias Marx

Hello NG

ASP:NET c# 1.1


I have to develop an existing c#, web application.
There is a datagrid.
With the Edit/Update function, where you could edit the value within the row.

I need a validation for numeric datatyp.
How could I insert a validation for this. It could be JavaScript, that onblur - event

With "normal" text boxes I do this
this.txtNumberRooms.Attributes.Add("onblur", "javascript:CheckNumber(this, 4);");

Thank You

But with the Datagrid i have now idea.



Regards

Matthias
 
J

Jo Inferis

Matthias said:
I need a validation for numeric datatyp.
How could I insert a validation for this. It could be JavaScript,
that onblur - event

With "normal" text boxes I do this
this.txtNumberRooms.Attributes.Add("onblur",
"javascript:CheckNumber(this, 4);");

woah there....there's a much simpler way to do this, and not just within a
DataGrid.

Use a System.Web.UI.WebControls.CompareValidator; something like this :

<asp:TextBox id="IntegerValue" runat="server"/>
<asp:CompareValidator
ControlToValidate="IntegerValue"
Operator="DataTypeCheck"
Type="Integer"
ErrorMessage="- you must provide a valid Integer Value"
Display="Static"
runat="server"/>

The compare validator can check String, Integer, Double, Date or Currency
data types. It also gives you the advantage of performing both client side
*and* server side validation for you. By checking Page.IsValid on postback
you'll know whether or not the data entered is valid according to the rules
you've set up.

With ASP.NET there's really no reason to write your own client-side
validation routines for trivial data-types (and non-trivial ones can usually
be coped with by judicious use of the RegularExpressionValidator).

HTH,
 
S

Shiva

Hi,
One option is to use EditItemTemplate for the grid. This lets you explicitly
specify the markup for the editable columns and hookup JS functions like
what you are looking for.

For a sample (at the bottom):
http://weblogs.asp.net/guys/articles/173646.aspx

Hello NG

ASP:NET c# 1.1


I have to develop an existing c#, web application.
There is a datagrid.
With the Edit/Update function, where you could edit the value within the
row.

I need a validation for numeric datatyp.
How could I insert a validation for this. It could be JavaScript, that
onblur - event

With "normal" text boxes I do this
this.txtNumberRooms.Attributes.Add("onblur", "javascript:CheckNumber(this,
4);");

Thank You

But with the Datagrid i have now idea.



Regards

Matthias
 
Joined
Oct 5, 2007
Messages
1
Reaction score
0
DataGrid Validation

Hi friend,
I was searching datagrid validation, but cud'nt get it. But i hav done validation in DataGrid.This validation work for float number. u can validate for every thing.

protected void CountryListGridView_RowUpdating(object sender, GridViewUpdateEventArgs e)
{

System.Collections.Specialized.IOrderedDictionary disc; //= new System.Collections.Specialized.IOrderedDictionary();
disc = e.NewValues;

try
{
float value = float.Parse(disc["price"].ToString());
}
catch (FormatException ex)
{
Response.Write("hello");
e.Cancel = true;
}




}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top