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

[Solved] Hide GridButtonColumn

5 Answers 478 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jones
Top achievements
Rank 1
Jones asked on 30 Sep 2009, 11:48 AM
Hello,

I have the following problem. I'm using a grid, where I have three GridButtonColumns, to Copy, Edit and Delete the record. When running the programm, I check if the current user is allowed to delete the reecord. If not, I want to hide the trash symbol in this cell. I want to clear the tooltip as well. Also, this cell uses the cursor pointer, I want to remove this as well. As result, I just will get an empty table cell, where you can't click on.

I hope you can help me, thanks in advance,

Regards, Jonas

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 30 Sep 2009, 12:24 PM
Hello Jonas,

You can actually hide the entire delete column, using its UniqueName property, when the user is restricred from delecting records as shown below:
c#:
protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
        //if(check for user) 
          RadGrid1.MasterTableView.GetColumn("ButtonColumn").Visible = false
 
    } 

Thanks
Princy.
0
Jones
Top achievements
Rank 1
answered on 30 Sep 2009, 12:53 PM
Hello,

thanks for the answer, but there I need the delete column. There may be some records, where the user can delete, and others where the user is not allowed to delete. It this case the user should see an empty cell, or something similar. It has to be obviously he has no rights to delete this record.

Thanks
0
Princy
Top achievements
Rank 2
answered on 01 Oct 2009, 08:12 AM
Hello Jonas,

Inorder to hide the delete button from a row based on a condition, you can try the following code:
c#:
 
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)  
    {  
      if(check for user)  
       {  
         if(e.Item is GridDataItem)  
             {  
               GridDataItem dataItem = (GridDataItem)e.Item;           
               ((ImageButton)dataItem["ButtonColumnUniqueName"].Controls[0]).Visible = false;  
               dataItem["ButtonColumnUniqueName"].Attributes.Add("onmouseover""this.style.cursor='text';");  
               dataItem["ButtonColumnUniqueName"].ToolTip = "";  
            }  
       }  
   }  

Thanks
Princy.
0
Jones
Top achievements
Rank 1
answered on 01 Oct 2009, 09:26 AM
Hello,

thanks for the answer. The images are indeed invisible,
unfortunately the whole cell is invisible which means, there are not table lines around the particular cells.
In the image provided you can see this problem.
0
Shinu
Top achievements
Rank 2
answered on 01 Oct 2009, 11:21 AM
Hi Jones,

The cell border seems to disappear when the cell is empty, so probably you can add a white space( ) to the cell inorder to prevent this. 
C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)   
    {   
      if(check for user)   
       {   
         if(e.Item is GridDataItem)   
             {   
               GridDataItem dataItem = (GridDataItem)e.Item;            
               ((ImageButton)dataItem["ButtonColumnUniqueName"].Controls[0]).Visible = false
 
               dataItem["ButtonColumnUniqueName"].Text = " " ;  
  
               dataItem["ButtonColumnUniqueName"].Attributes.Add("onmouseover""this.style.cursor='text';");   
               dataItem["ButtonColumnUniqueName"].ToolTip = "";   
            }   
       }   
   }   

Hope this helps..
-Shinu.
Tags
Grid
Asked by
Jones
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Jones
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or