Conditional Delete buttons - c#

J

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
 
M

Morgan

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
 
J

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top