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

Hide delete button on some rows?

2 Answers 1343 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Leon Ham
Top achievements
Rank 1
Leon Ham asked on 20 Feb 2009, 01:30 PM
Hi,

Is it possible to hide the delete button on some rows in the grid?

I'm hiding the button in the ItemDataBound function, but when a row is clicked in the grid, the delete image is shown again.

Can anybody give me a sollution?

The RadGrid ClientSettings are:
<ClientSettings EnablePostBackOnRowClick="True" EnableRowHoverStyle="True">  
   <Selecting AllowRowSelect="True" /> 
   <Scrolling AllowScroll="True" UseStaticHeaders="True" /> 
</ClientSettings> 

Thanks

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 20 Feb 2009, 01:55 PM
Hi Leon Ham,

I tried the following code in the ItemDataBound event of the RadGrid and its working as expected. Check for any differences with your code.

ASPX:
<telerik:GridButtonColumn ButtonType="LinkButton" Text="Delete" UniqueName="Delete" CommandName="Delete" > 
</telerik:GridButtonColumn> 
<telerik:GridBoundColumn DataField="User" HeaderText="User" UniqueName="User"
</telerik:GridBoundColumn> 

CS:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    if (e.Item is GridDataItem) 
    { 
        GridDataItem item = (GridDataItem)e.Item; 
        LinkButton deleteButton = (LinkButton)item["Delete"].Controls[0]; 
        if (item["User"].Text == "Non-Admin"
        { 
            deleteButton.Visible = false
        } 
    } 

Thanks,
Shinu.
0
Leon Ham
Top achievements
Rank 1
answered on 20 Feb 2009, 02:07 PM
Hi,

My code does something extra. Here is my code:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)    
{    
    if (e.Item is GridDataItem)    
    {  
        DataRowView item = (DataRowView)e.Item.DataItem;  
        if (item != null)  
        {  
            // "SystemGroup"  
            if ((bool)item["SystemGroup"] == true)  
            {  
                // Disable delete  
                TableCell cell = ((GridDataItem)e.Item)["delete"];  
                ImageButton deleteButton = (ImageButton)cell.Controls[0];  
                deleteButton.Visible = false;  
                deleteButton.Enabled = false;  
                cell.Text = "&nbsp;";  
        }  
    }  
}  
 

This code shows the Delete button again if clicked on the row.
If the last line with cell.Text = "&nbsp;"; is removed, then everything is working as expected, but the layout of the row is less good.

Thanks
Tags
Grid
Asked by
Leon Ham
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Leon Ham
Top achievements
Rank 1
Share this question
or