473,406 Members | 2,451 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,406 software developers and data experts.

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 4659
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.WebControls.DataGridItemEventArgs) Handles
grdInvoiceLines.ItemDataBound
Select Case e.Item.ItemType
Case ListItemType.Item, ListItemType.AlternatingItem
Dim myTableCell As TableCell
myTableCell = e.Item.Cells(6)
Dim myDeleteButton As ImageButton
myDeleteButton = CType(myTableCell.Controls(1),
System.Web.UI.WebControls.ImageButton)
If _IsPaid = True Then
Dim mylbl As Label
mylbl = CType(myEditCell.Controls(1), System.Web.UI.WebControls.Label)
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*********@btinternet.com> wrote in message
news:d7**************************@posting.google.c om...
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.WebControls.DataGridItemEventArgs) Handles
grdInvoiceLines.ItemDataBound
Select Case e.Item.ItemType
Case ListItemType.Item, ListItemType.AlternatingItem
Dim myTableCell As TableCell
myTableCell = e.Item.Cells(6)
Dim myDeleteButton As ImageButton
myDeleteButton = CType(myTableCell.Controls(1),
System.Web.UI.WebControls.ImageButton)
If _IsPaid = True Then
Dim mylbl As Label
mylbl = CType(myEditCell.Controls(1), System.Web.UI.WebControls.Label)
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*********@btinternet.com> wrote in message
news:d7**************************@posting.google.c om...
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
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...
3
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
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...
3
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,...
3
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....
2
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...
4
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...
4
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...
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
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...

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.