This is a migrated thread and some comments may be shown as answers.

[Solved] Conditionally showing Delete Icon on row

2 Answers 276 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brian
Top achievements
Rank 1
Brian asked on 17 Feb 2010, 12:01 PM
I have a grid, which has the following GridButtonColumn defined:

                <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete" ConfirmText="Delete this selector?" 
                    Text="Delete" UniqueName="DeleteColumn"
                    <ItemStyle CssClass="EditImageButton" HorizontalAlign="Center" /> 
                </telerik:GridButtonColumn> 
>

On some rows that are shown in the grid I would like to hide the DeleteButton (i.e. these are rows that can't be deleted by the user)  -- how do I conditionally hide the delete button?

Thankyou.

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 17 Feb 2010, 12:14 PM
Hi Brian,

Use the following code snippet in order to show/hide the delete button based on the value in row.

C#:
 
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem item = (GridDataItem)e.Item; 
                if (Convert.ToInt32(item["Age"].Text) > 20) 
                { 
                    ImageButton btn = (ImageButton)item["DeleteColumn"].Controls[0]; 
                    btn.Visible = false
                } 
        } 
 
    } 

-Shinu.
0
Brian
Top achievements
Rank 1
answered on 18 Feb 2010, 04:31 PM
That worked wonderfully - thankyou.

Brian
Tags
Grid
Asked by
Brian
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Brian
Top achievements
Rank 1
Share this question
or