DataGrid Button Validation Problem

T

Tina

the Edit, Update, Cancel, and Delete buttons in my datagrid are causing
validation elsewhere on the page. I want to specify that these buttons
should not cause validation but they have no design time property of
causevalidation.

How can I keep them from causing validation?

Thanks,
T
 
G

Guest

In ItemDataBound or ItemCreated event, you can get Edit button reference by

LinkButton editBtn = (LinkButton)e.Item.Cells[edit_column_index].Controls[0];
editBtn.CausesValidation = false;

But in order to get refernce of Update / Canel button, you need to do it in
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;

HTH

Elton Wang
 
T

Tina

Elton,
Im using vb..

Actually only the Update button causes validation as the others already are
set to not cause validation. My problem, however, is
that in the EditCommand event
myDataGrid.Items(e.Item.ItemIndex).Cells(0).Controls(0) has
in it the Edit button and
myDataGrid.Items(e.Item.ItemIndex).Cells(1).Controls(0) has the Cancel
button in it. Those buttons are already set to CausesValidation = false.

I have fished everywhere but I can't find the Update button!

Still looking,
T



Elton W said:
In ItemDataBound or ItemCreated event, you can get Edit button reference
by

LinkButton editBtn =
(LinkButton)e.Item.Cells[edit_column_index].Controls[0];
editBtn.CausesValidation = false;

But in order to get refernce of Update / Canel button, you need to do it
in
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;

HTH

Elton Wang

Tina said:
the Edit, Update, Cancel, and Delete buttons in my datagrid are causing
validation elsewhere on the page. I want to specify that these buttons
should not cause validation but they have no design time property of
causevalidation.

How can I keep them from causing validation?

Thanks,
T
 
P

Patrick.O.Ige

If you don't have an insert button you can just set your Delete button to
DelBtn.CausesValidation = false;
Patrick
 
G

Guest

If you are using EditCommandColumn in first column, you can get Update and
Cancel buttons by following code in EditCommand event.

' Update button normally is in the first control
Dim updateBtn As LinkButton =
CType(myDataGrid.Items(e.Item.ItemIndex).Cells(0).Controls(0), LinkButton)

'cancel button in 3rd control (2nd control is a Literal control, like space,
or you can try cast 2nd control to button)
Dim cancelBtn As LinkButton =
CType(myDataGrid.Items(e.Item.ItemIndex).Cells(0).Controls(2), LinkButton)

HTH

Elton


Tina said:
Elton,
Im using vb..

Actually only the Update button causes validation as the others already are
set to not cause validation. My problem, however, is
that in the EditCommand event
myDataGrid.Items(e.Item.ItemIndex).Cells(0).Controls(0) has
in it the Edit button and
myDataGrid.Items(e.Item.ItemIndex).Cells(1).Controls(0) has the Cancel
button in it. Those buttons are already set to CausesValidation = false.

I have fished everywhere but I can't find the Update button!

Still looking,
T



Elton W said:
In ItemDataBound or ItemCreated event, you can get Edit button reference
by

LinkButton editBtn =
(LinkButton)e.Item.Cells[edit_column_index].Controls[0];
editBtn.CausesValidation = false;

But in order to get refernce of Update / Canel button, you need to do it
in
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;

HTH

Elton Wang

Tina said:
the Edit, Update, Cancel, and Delete buttons in my datagrid are causing
validation elsewhere on the page. I want to specify that these buttons
should not cause validation but they have no design time property of
causevalidation.

How can I keep them from causing validation?

Thanks,
T
 
T

Tina

Thanks for getting me started on this problem. The way it worked out for me
was a little different than what your examples show....

in the EditCommand event I can get e.item.itemindex which tells me which row
is being edited (of course) but I could not find the Update button because
in the Edititem event it's not there yet. So I saved the line number
then...

in the ItemDataBound event, which gets visited once for every line, if it's
my line number, then the update button can be found and that is where I was
able to set CausesValidation to false.

So, it works now and fortunitely I don't have any validators in the
itemtemplates so I don't need for that button to validate. The permanent
solution, I think, is that there should be a smaller scope for validation
than the page.

Anyway, thanks for the help.
T

Elton W said:
If you are using EditCommandColumn in first column, you can get Update and
Cancel buttons by following code in EditCommand event.

' Update button normally is in the first control
Dim updateBtn As LinkButton =
CType(myDataGrid.Items(e.Item.ItemIndex).Cells(0).Controls(0), LinkButton)

'cancel button in 3rd control (2nd control is a Literal control, like
space,
or you can try cast 2nd control to button)
Dim cancelBtn As LinkButton =
CType(myDataGrid.Items(e.Item.ItemIndex).Cells(0).Controls(2), LinkButton)

HTH

Elton


Tina said:
Elton,
Im using vb..

Actually only the Update button causes validation as the others already
are
set to not cause validation. My problem, however, is
that in the EditCommand event
myDataGrid.Items(e.Item.ItemIndex).Cells(0).Controls(0) has
in it the Edit button and
myDataGrid.Items(e.Item.ItemIndex).Cells(1).Controls(0) has the Cancel
button in it. Those buttons are already set to CausesValidation = false.

I have fished everywhere but I can't find the Update button!

Still looking,
T



Elton W said:
In ItemDataBound or ItemCreated event, you can get Edit button
reference
by

LinkButton editBtn =
(LinkButton)e.Item.Cells[edit_column_index].Controls[0];
editBtn.CausesValidation = false;

But in order to get refernce of Update / Canel button, you need to do
it
in
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;

HTH

Elton Wang

:

the Edit, Update, Cancel, and Delete buttons in my datagrid are
causing
validation elsewhere on the page. I want to specify that these
buttons
should not cause validation but they have no design time property of
causevalidation.

How can I keep them from causing validation?

Thanks,
T
 

AJC

Joined
Jan 5, 2009
Messages
1
Reaction score
0
Hello, Tina,
I would like to know how could you use linkbuttom to fire validations in datagrid.
Thank you.
 

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,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top