How to validate input in gridview edit mode

I

ibiza

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
 
I

ibiza

thank you very much Phillip,

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

you are so helpful to me! :)

Bruno
 
G

Guest

No, you cannot do it with a boundfield. You have to replace the boundfield
with a TemplateField if you wish to add validation controls.
 
Joined
Jan 11, 2011
Messages
1
Reaction score
0
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;
}
 

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,997
Messages
2,570,239
Members
46,828
Latest member
LauraCastr

Latest Threads

Top