D
Dan
Hi all, I have a question about datagrid: let's say I have a datagrid which
shows the categories for some items; each category has an ID field and a
description. I use an ASP.NET page with a datagrid bound to this table to
show, edit or delete any row in this table. I have made a template of the
edit/cancel column to be able to check for invalid values (e.g. an empty or
duplicate category), using validators referring to the edit control of my
edit template.
All this works fine, my question is: I'd like to Disable the delete command
for all the rows which are assigned to some items in the database, so that
it will not be possible to delete a category without first modifying all the
items assigned to it. Anyway, the user will be able to delete unused
categories, either existing or inserted by himself in the same page. Of
course the test function is trivial, but how can I trigger it when user
clicks Delete? I could think of 2 possible scenarios:
1) validation-like mechanism: when user clicks Delete the check will be
triggered and if it fails a validation error should be displayed in the row
and the deletion should not be performed. Anyway, how can I implement a
validation mechanism without having any control to be validated? Here it is
not the case of validating e.g. the textbox with the category name to be
updated, but I must check the availability of a command when the user clicks
on a button.
2) another (even better) way could be preventing the datagrid from inserting
the Delete button in the template whenever the row being shown cannot be
deleted according to the specified test. Is this possible?
Is there any way of doing any of the two tasks? Or should I try a totally
different way? Thanks!
shows the categories for some items; each category has an ID field and a
description. I use an ASP.NET page with a datagrid bound to this table to
show, edit or delete any row in this table. I have made a template of the
edit/cancel column to be able to check for invalid values (e.g. an empty or
duplicate category), using validators referring to the edit control of my
edit template.
All this works fine, my question is: I'd like to Disable the delete command
for all the rows which are assigned to some items in the database, so that
it will not be possible to delete a category without first modifying all the
items assigned to it. Anyway, the user will be able to delete unused
categories, either existing or inserted by himself in the same page. Of
course the test function is trivial, but how can I trigger it when user
clicks Delete? I could think of 2 possible scenarios:
1) validation-like mechanism: when user clicks Delete the check will be
triggered and if it fails a validation error should be displayed in the row
and the deletion should not be performed. Anyway, how can I implement a
validation mechanism without having any control to be validated? Here it is
not the case of validating e.g. the textbox with the category name to be
updated, but I must check the availability of a command when the user clicks
on a button.
2) another (even better) way could be preventing the datagrid from inserting
the Delete button in the template whenever the row being shown cannot be
deleted according to the specified test. Is this possible?
Is there any way of doing any of the two tasks? Or should I try a totally
different way? Thanks!