RequiredfiledValidator and regularexpressionvalidator in DataGrid footer

P

Patrick.O.Ige

I have a Datagrid with Update,Delete and Edit buttons.
And on the footer i'm adding a new ROW to the DataGrid
I placed RequiredfiledValidator and regularexpressionvalidator in the Footer
of a DataGrid
so that i can validate the TextBoxes but when i click the Submit button in
the Footer it doesn't fire but then i click the
the Delete button on any ROW of the Datagrid it fires the
RequiredfiledValidator in the footer..
Any ideas ?
 
E

Elton Wang

Check the button's CausesValidation property. If it's set to false, it
doesn't fire validation.

HTH
 
P

Patrick.O.Ige

Thanks Elton for the reply..but my detailed question is below:-

I have a Datagrid with Update/Edit/Cancel in the EditCommandColumn
And an insert Button in the footer to add new record..
I have set RequiredFieldValidator in the FOOTER to validate text
fields before inserting data..
Now i added another ones in the EditTemplate to check values before
updating...
When i Click on the Update button in the EditCommandColumn
it triggers the requiredfiledvalidator for the insert button and text
fileds.
How can i access the update button in the EditCommandColumn in the
edit mode?
Or how can i set the insert button in the footer to
CausesValidation=False when the update button is in the edit mode..??
 
E

Elton Wang

Hi Patrick,

It's a little trick. Before a row becomes Edit state, the update button is
no available. So one way to do it is that in DataGrid_EditCommand event:

DataGrid.EditItemIndex = e.Item.ItemIndex;
DataGrid.DataSource = dataObj;
DataGrid.DataBind();
// up to now the e.Item.ItemIndex row of DataGrid becomes edit state. But
e.Item is still in normal state. So you need get Update button from datagrid
LinkButton updateBtn =
(LinkButton)this.DataGrid.Items[e.Item.ItemIndex].Cells[button_col_index].Controls[0];
// then set its CausesValidation
updateBtn.CausesValidation = true/false;

If you have ID for the insert button in footer, you meight use

DataGrid.FindControl("insert_button_ID") to refer the button.

HTH
 
P

Patrick.O.Ige

Thx Elto i figured it out.
I actually noticed that problem when i had to make use of Validators in both
the insert and Edit /update mode.
What actually i did earlier was to set the SHOWFOOTER visible=false when in
edit mode and that worked.
But if i set my update button to CausesValidation=false as you requested my
validators won't fire.
Unless i set the insert button in the FOOTER to CausesValidation=false when
in Edit mode.
Patrick



Elton Wang said:
Hi Patrick,

It's a little trick. Before a row becomes Edit state, the update button is
no available. So one way to do it is that in DataGrid_EditCommand event:

DataGrid.EditItemIndex = e.Item.ItemIndex;
DataGrid.DataSource = dataObj;
DataGrid.DataBind();
// up to now the e.Item.ItemIndex row of DataGrid becomes edit state. But
e.Item is still in normal state. So you need get Update button from datagrid
LinkButton updateBtn =
(LinkButton)this.DataGrid.Items[e.Item.ItemIndex].Cells[button_col_index].Co
ntrols[0];
// then set its CausesValidation
updateBtn.CausesValidation = true/false;

If you have ID for the insert button in footer, you meight use

DataGrid.FindControl("insert_button_ID") to refer the button.

HTH


Patrick.O.Ige said:
Thanks Elton for the reply..but my detailed question is below:-

I have a Datagrid with Update/Edit/Cancel in the EditCommandColumn
And an insert Button in the footer to add new record..
I have set RequiredFieldValidator in the FOOTER to validate text
fields before inserting data..
Now i added another ones in the EditTemplate to check values before
updating...
When i Click on the Update button in the EditCommandColumn
it triggers the requiredfiledvalidator for the insert button and text
fileds.
How can i access the update button in the EditCommandColumn in the
edit mode?
Or how can i set the insert button in the footer to
CausesValidation=False when the update button is in the edit mode..??



button
in
 

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

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top