473,546 Members | 2,205 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Conditional Delete buttons - c#

JC
Hi,

I am using a Datagrid and populating it from a database.

I have a 'delete' button column, and when click it executes the
DeleteCommand event. My problem is I would like this button to appear
only in rows when a condition is met and I'm not sure how to
accomplish this.

The default behaviour is to appear in every row on the datagrid.

I'm working and in c# and any help would be gratefully recieved.

Thanks

James
Nov 18 '05 #1
3 4666
Sure, you can use the ItemDataBound event, sorry but it's in VB, maybe this
will get you started, though.

What you could do is have a hidden label in one of the grid columns and set
it's value equal to the conditional to show or hide the delete button. Then,
in the ItemDataBound event, you can read the lable, check the value and
conditionally make the delete button visible.

HTH,

Morgan
Private Sub grdInvoiceLines _ItemDataBound( ByVal sender As Object, ByVal e As
System.Web.UI.W ebControls.Data GridItemEventAr gs) Handles
grdInvoiceLines .ItemDataBound
Select Case e.Item.ItemType
Case ListItemType.It em, ListItemType.Al ternatingItem
Dim myTableCell As TableCell
myTableCell = e.Item.Cells(6)
Dim myDeleteButton As ImageButton
myDeleteButton = CType(myTableCe ll.Controls(1),
System.Web.UI.W ebControls.Imag eButton)
If _IsPaid = True Then
Dim mylbl As Label
mylbl = CType(myEditCel l.Controls(1), System.Web.UI.W ebControls.Labe l)
mylbl.Visible = False
myDeleteButton. Visible = False
Else
myDeleteButton. Attributes.Add( "onclick", "return confirm('Are you Sure you
want to delete this Line Item?');")
End If
End Select
End Sub

"JC" <ja*********@bt internet.com> wrote in message
news:d7******** *************** ***@posting.goo gle.com...
Hi,

I am using a Datagrid and populating it from a database.

I have a 'delete' button column, and when click it executes the
DeleteCommand event. My problem is I would like this button to appear
only in rows when a condition is met and I'm not sure how to
accomplish this.

The default behaviour is to appear in every row on the datagrid.

I'm working and in c# and any help would be gratefully recieved.

Thanks

James

Nov 18 '05 #2
Sure, you can use the ItemDataBound event, sorry but it's in VB, maybe this
will get you started, though.

What you could do is have a hidden label in one of the grid columns and set
it's value equal to the conditional to show or hide the delete button. Then,
in the ItemDataBound event, you can read the lable, check the value and
conditionally make the delete button visible.

HTH,

Morgan
Private Sub grdInvoiceLines _ItemDataBound( ByVal sender As Object, ByVal e As
System.Web.UI.W ebControls.Data GridItemEventAr gs) Handles
grdInvoiceLines .ItemDataBound
Select Case e.Item.ItemType
Case ListItemType.It em, ListItemType.Al ternatingItem
Dim myTableCell As TableCell
myTableCell = e.Item.Cells(6)
Dim myDeleteButton As ImageButton
myDeleteButton = CType(myTableCe ll.Controls(1),
System.Web.UI.W ebControls.Imag eButton)
If _IsPaid = True Then
Dim mylbl As Label
mylbl = CType(myEditCel l.Controls(1), System.Web.UI.W ebControls.Labe l)
mylbl.Visible = False
myDeleteButton. Visible = False
Else
myDeleteButton. Attributes.Add( "onclick", "return confirm('Are you Sure you
want to delete this Line Item?');")
End If
End Select
End Sub

"JC" <ja*********@bt internet.com> wrote in message
news:d7******** *************** ***@posting.goo gle.com...
Hi,

I am using a Datagrid and populating it from a database.

I have a 'delete' button column, and when click it executes the
DeleteCommand event. My problem is I would like this button to appear
only in rows when a condition is met and I'm not sure how to
accomplish this.

The default behaviour is to appear in every row on the datagrid.

I'm working and in c# and any help would be gratefully recieved.

Thanks

James

Nov 18 '05 #3
JC
Hi Morgan,

That is a great start, I should be able to get there with that -
thanks for your help, much appreciated.

Yours

James
Nov 18 '05 #4

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

Similar topics

1
4300
by: Orest Kinasevych | last post by:
Okay, I made sense of the earlier suggestions and realized I was on the right track -- I appreciate the feedback which got me to this point. The suggestions posted here indeed worked and eliminated the JavaScript errors I was seeing. The fact that the target URL didn't execute was because certain variables weren't being passed to it. ...
3
10958
by: David Link | last post by:
Hi All, Here's a Conditional drop_table func for those interested. There was a thread on this a long time back. We do this all the time : DELETE TABLE sales; CREATE TABLE sales (...);
3
5921
by: Jouke Langhout | last post by:
Hello all! For quite some time now, I've got the following problem: Access won't close properly when a user closes the application. An ACCESS process stays active and that process can only be terminated by pressing ++ and then terminate the process. I searched the entire internet and found out that there could be two things wrong (both...
3
2777
by: vcornjamb | last post by:
Hello, I am developing a web form that contains some buttons and a data grid which has as its last column link buttons that will delete the data associated with that row. Everything works fine, but users have requested a confirmation message pop up so the user can confirm the delete. I can not quite get this to work. Here are the facts:...
3
13728
by: NateDawg | last post by:
I'm reposting this. I'm kinda in a bind untill i get this figured out, so if anyone has some input it would sure help me out. Ok, I’ve noticed a few gridview problems floating around the forum. Everyone wants to do a java confirmation box when a user clicks the delete button. Fair enough, basic user design rules state that you should...
2
1248
by: mike.aes | last post by:
(Using VS.Net 2005) What are the best practices for conditionally turning on/off INSERT/EDIT/DELETE features in the Datagrid and Detailsview controls? In other words, depending on a user's security level, certain insert/edit/delete buttons should be made invisible. I don't see a way to do with within the HTML of the Datagrid control. ...
4
1906
by: AA Arens | last post by:
I amde a helpdesk database and on the calls form I put record navigation buttons / / / / / / Is het possible to navigate / through the records with a certain status. Each call has a certain status with is set via an Option Group and filled in the Status colomn in the Calls table. Bart
4
2283
by: wim taerwe | last post by:
Hello, I am looking for an easy way to have a delete button per subitem in 1 form. For example : a book can have many authors and when I edit the book details I want to have a list of the authors each with a separate delete-submitbutton next to it. Now I have the problem that I cannot know which exact author I want to delete when I click...
2
8604
by: Lyn | last post by:
Hi, Having fun trying to get Conditional Formatting working on a textbox control in a continuous form subform (Access 2003). The condition I want is when the value of the textbox is Null and/or an empty string. 1) Using Access: I select "Field value is" and "equal to". Not sure what to put in the Expression1 field. Have tried leaving it...
0
7507
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...
0
7698
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. ...
0
7794
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...
0
6030
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5361
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...
0
5080
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3492
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...
0
3472
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1046
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.