Connecting Tech Pros Worldwide Forums | Help | Site Map

Conditional Delete buttons - c#

JC
Guest
 
Posts: n/a
#1: Nov 18 '05
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

Morgan
Guest
 
Posts: n/a
#2: Nov 18 '05

re: Conditional Delete buttons - c#


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" <james_crane@btinternet.com> wrote in message
news:d73038d8.0401220930.410c98bf@posting.google.c om...[color=blue]
> 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[/color]


Morgan
Guest
 
Posts: n/a
#3: Nov 18 '05

re: Conditional Delete buttons - c#


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" <james_crane@btinternet.com> wrote in message
news:d73038d8.0401220930.410c98bf@posting.google.c om...[color=blue]
> 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[/color]


JC
Guest
 
Posts: n/a
#4: Nov 18 '05

re: Conditional Delete buttons - c#


Hi Morgan,

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

Yours

James
Closed Thread