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

DataGrid Button Validation Problem

P: n/a
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
Nov 20 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a

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" wrote:
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

Nov 20 '05 #2

P: n/a
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).Contro ls(0) has
in it the Edit button and
myDataGrid.Items(e.Item.ItemIndex).Cells(1).Contro ls(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" <El****@discussions.microsoft.com> wrote in message
news:CF**********************************@microsof t.com...

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" wrote:
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

Nov 20 '05 #3

P: n/a
If you don't have an insert button you can just set your Delete button to
DelBtn.CausesValidation = false;
Patrick

"Tina" <ti**********@nospammeexcite.com> wrote in message
news:uI**************@TK2MSFTNGP10.phx.gbl...
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

Nov 20 '05 #4

P: n/a
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" wrote:
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).Contro ls(0) has
in it the Edit button and
myDataGrid.Items(e.Item.ItemIndex).Cells(1).Contro ls(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" <El****@discussions.microsoft.com> wrote in message
news:CF**********************************@microsof t.com...

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" wrote:
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


Nov 20 '05 #5

P: n/a
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" <El****@discussions.microsoft.com> wrote in message
news:74**********************************@microsof t.com...
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" wrote:
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).Contro ls(0) has
in it the Edit button and
myDataGrid.Items(e.Item.ItemIndex).Cells(1).Contro ls(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" <El****@discussions.microsoft.com> wrote in message
news:CF**********************************@microsof t.com...
>
> 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" wrote:
>
>> 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
>>
>>
>>


Nov 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.