473,414 Members | 1,862 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

datagrid templates and deletion

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!
Nov 19 '05 #1
1 1254
Dan wrote:
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!


2) certainly is possible.

If your SQL SELECT command is something like this:
SELECT ID,Category FROM Categories;

change it into something like this:
SELECT ID,Category,(SELECT COUNT(*) FROM Items WHERE
CategoryID=Categories.ID) AS nItems FROM Categories;

Then, bind the Visible property of your delete button like this:
Visible='<%# DataBinder.Eval(Container.DataItem,"nItems")>0 %>'

--

Riki
Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Chumley the Walrus | last post by:
IN my code behind .vb page for a delete records script (this also does a deletion confirmation with a javascript popup, this gets called on my front .aspx page with the datagrid), I'm not sure if...
9
by: Pam Ammond | last post by:
After clicking btnDeleteSize_Click in frmSize, I move to frmSizeDelete, allow deleting a Size using a datagrid, and then return to frmSize and want to update the datagrid in frmSize to reflect the...
4
by: Rod | last post by:
I posted a message to this group yesterday asking how to pass parameters to a web form that is the source of an IFrame on a parent web form. I've gotten my answer, and it works. Thanks! Now I...
6
by: JenHu | last post by:
Hi experts, I want to add a delete button in my datagrid, and before it deletes from database, I want to have a confirm dialog box for this deletion. I am entry level to the vb.net, and don't...
1
by: mike | last post by:
I posted before and got the reply below, which really doesn't help me at all. I really didn't understand what the responder was talking about I'd like someone who is a microsoft expert to help...
0
by: Mike Bravo | last post by:
When I delete a row from my dataset, using 'Delete the current row Dim ll_cur_row As Long ll_cur_row = Dg_base1.CurrentRowIndex() If ll_cur_row >= 0 Then
0
by: excelleinc.com | last post by:
Hello, I know that this question was here quite a few times but I was wondering if anyone atually found a solution/work around for it. I'm trying to prevent users from deleting certain rows in...
0
by: slemen | last post by:
Hi, The DataGrid aps:EditCommandColumn when used with column templates created programmatically does not trigger the _Edit subroutine in code. The ASP:Datagrid definition is below (1), the...
4
by: mamun | last post by:
Hi All, I have the following situation and am looking for answer in C#. I have a datagrid and putting checkbox next to each record. In the header I have a Delete button. I want users to...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.