Conditional Delete buttons - c#

  • Thread starter Thread starter JC
  • Start date Start date
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
 
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
 
Hi Morgan,

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

Yours

James
 
Back
Top