By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,201 Members | 1,617 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,201 IT Pros & Developers. It's quick & easy.

Validation for DataGrid

P: n/a
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



Nov 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Matthias Marx wrote:
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,
--
jo inferis
Nov 18 '05 #2

P: n/a
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

"Matthias Marx" <ma***********@nospam.gmx.net> wrote in message
news:uv**************@TK2MSFTNGP09.phx.gbl...
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




Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.