Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How to validate input in gridview edit mode

Reply
Thread Tools

How to validate input in gridview edit mode

 
 
ibiza
Guest
Posts: n/a
 
      01-19-2006
Hi all,

I have a gridview that can edit data, which is bound to an
sqldatasource. Everything works fine, I can update the data via an Edit
Command field.

However, there are some textboxes in edit mode which I would like to
validate. For example, one of the is required and cannot be left empty.
How can I make such validation in edit mode in a gridview?

Thanks in advance,

Bruno

 
Reply With Quote
 
 
 
 
=?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
Guest
Posts: n/a
 
      01-20-2006
Hi Bruno,

You do it by adding your validation controls within the template field like
I did for checking the dates with comparevalidators in this demo:
http://www.webswapp.com/CodeSamples/...idView_2c.aspx
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


"ibiza" wrote:

> Hi all,
>
> I have a gridview that can edit data, which is bound to an
> sqldatasource. Everything works fine, I can update the data via an Edit
> Command field.
>
> However, there are some textboxes in edit mode which I would like to
> validate. For example, one of the is required and cannot be left empty.
> How can I make such validation in edit mode in a gridview?
>
> Thanks in advance,
>
> Bruno
>
>

 
Reply With Quote
 
 
 
 
ibiza
Guest
Posts: n/a
 
      01-20-2006
thank you very much Phillip,

I guess there are no way to do it with a boundfield.

you are so helpful to me!

Bruno

 
Reply With Quote
 
=?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
Guest
Posts: n/a
 
      01-20-2006
No, you cannot do it with a boundfield. You have to replace the boundfield
with a TemplateField if you wish to add validation controls.
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


"ibiza" wrote:

> thank you very much Phillip,
>
> I guess there are no way to do it with a boundfield.
>
> you are so helpful to me!
>
> Bruno
>
>

 
Reply With Quote
 
ibiza
Guest
Posts: n/a
 
      01-20-2006
Thank you very much Phillip.

As you seem very knowledgeable, would you know the answer of this
situation, by any means?

http://groups.google.ca/group/micros...5e89eb504d5fef

I still have this problem and can't find any way to resolve
it...thanks!

ibiza

 
Reply With Quote
 
=?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
Guest
Posts: n/a
 
      01-20-2006
http://www.webswapp.com/CodeSamples/...alidation.aspx

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


"ibiza" wrote:

> Thank you very much Phillip.
>
> As you seem very knowledgeable, would you know the answer of this
> situation, by any means?
>
> http://groups.google.ca/group/micros...5e89eb504d5fef
>
> I still have this problem and can't find any way to resolve
> it...thanks!
>
> ibiza
>
>

 
Reply With Quote
 
ibiza
Guest
Posts: n/a
 
      01-20-2006
wow thank you!

I wonder why I did'nt think of this simple solution by myself

 
Reply With Quote
 
jasonHall jasonHall is offline
Junior Member
Join Date: Jan 2011
Posts: 1
 
      01-11-2011
A technique that worked well for me for validating BoundFields is to perform the validation in the gridView_RowUpdating event handler. "e" is the GridViewUpdateEventArgs. I just show the error message in red and display it to the user right in the textbox, and keep the Row in edit mode.

Code:
GridViewRow aRow = gvBatchDetails.Rows[e.RowIndex];

if (((TextBox)(aRow.Cells[1].Controls[0])).Text == "hello")
{
    ((TextBox)(aRow.Cells[1].Controls[0])).Text = "Error";
    ((TextBox)(aRow.Cells[1].Controls[0])).ForeColor = System.Drawing.Color.Red;
    e.Cancel = true;
}
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
GridView control enters edit mode when I click Edit link twice Jaime Stuardo ASP .Net Web Controls 0 04-07-2006 12:47 AM
Snapshot restraint - edit, edit, edit Alan Browne Digital Photography 24 05-10-2005 10:15 PM
Snapshot restraint - edit, edit, edit Patrick Digital Photography 0 05-06-2005 10:53 PM
Would like to load a datagrid already in edit mode instead of having the user click the edit button Frank Kurka ASP .Net Datagrid Control 8 04-29-2005 09:33 AM
How to validate a datagrid (in edit mode)? Ante Perkovic ASP .Net 0 06-24-2003 10:05 AM



Advertisments