473,761 Members | 4,407 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1279
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,(SE LECT COUNT(*) FROM Items WHERE
CategoryID=Cate gories.ID) AS nItems FROM Categories;

Then, bind the Visible property of your delete button like this:
Visible='<%# DataBinder.Eval (Container.Data Item,"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
2230
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 he row.delete() in my Delete_Row sub is correct because when deleting a record from the dbase, it doesnot get deleted from the actual database, even tho on the datagrid it does show that the record is deleted: '''''''''''''
9
1646
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 deletion. I can't figure out how to get the datagrid in frmSize updated, although the datagrid in frmSizeDelete shows the deletion properly. In frmSizeDelete the size is properly deleted when the user clicks the row in the datagrid and presses...
4
2130
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 have a different problem. The web form that is in the IFrame has a DataGrid in it. I have a button column in it which I use to trigger the deletion of the row in the database, and I want it to also reflect that deletion in the data grid. The...
6
4638
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 know java or c#. The problem is, when I tested the program, there is no pop-up confirmation box for the deletion, can you show me what' wrong with this code? Thank you.
1
1755
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 me with some specifics on this problem: I have to do some specific data verification before saving a row or group of rows to the database (the data validation in the datagrid really doesn't help all that
0
1272
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
996
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 datagrid. This rows are specified in rownumber property. To do this I have implemented custom datagrid that looks like this: Class DGCustom
0
1244
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 _Edit subroutine signature (2) is below that and the column template class is (3). Thank you for your help, Scott
4
7502
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 checkchekboxes and click the Delete button. That will show a confirmation dialog message with the items they choose to delete.
0
9531
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9345
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10115
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9957
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9775
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7332
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5229
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3881
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2752
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.