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

How to hide LinkButton on some rows?

4 Answers 393 Views
Grid
This is a migrated thread and some comments may be shown as answers.
James O'Brien
Top achievements
Rank 1
James O'Brien asked on 21 Apr 2010, 10:52 PM
I'm using the RadGrid and I'm using a GridButtonColumn ButtonType="LinkButton" in it. I want to be able to hide this control on some rows, mainly the first and last ... but I want to know how to do it on any row or any type of control.

Thank you

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 22 Apr 2010, 04:50 AM
Hello James,

You can hide the LinkButton control based on condition, by using following code:

aspx:

<
telerik:GridButtonColumn ButtonType="LinkButton" Text="delete" CommandName="Delete" UniqueName="LinkButton1"></telerik:GridButtonColumn> 

CS:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            if (condition)//check for the condition 
            { 
            GridDataItem item = (GridDataItem)e.Item; 
            LinkButton btn = (LinkButton)item["LinkButton1"].Controls[0]; 
            btn.Visible = false
            } 
        } 
    } 

Regards,
Shinu.
0
James O'Brien
Top achievements
Rank 1
answered on 26 Apr 2010, 06:49 PM
Thanks Shinu

I get a "Cannot find a cell bound to column name 'LinkButton1'" or whatever I name it. Because it loops thru other controls and then errors.

Thank you

protected void RadGrid_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            foreach (GridDataItem item in gridAnnouncements.MasterTableView.Items) 
            { 
                if (item.ItemIndex == 0) 
                { 
                    LinkButton btn = (LinkButton)item["UpAnnouncement"].Controls[0]; 
                    btn.Visible = false
                    item.Display = false
                    break; //terminates the for loop 
                } 
            }   
        } 
    } 

0
Shinu
Top achievements
Rank 2
answered on 27 Apr 2010, 08:50 AM
Hi James,

I am not quite sure about what is happening at your end, but please make sure that you have used same name for ColumnUniqueName and when accessing the control in ItemDataBound event.

aspx:-
 
<telerik:GridButtonColumn UniqueName="UpAnnouncement" ButtonType="LinkButton" Text="xxx" /> 

cs:-
 
    protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem item = (GridDataItem)e.Item; 
            if (item.ItemIndex == 0) 
            { 
                LinkButton btn = (LinkButton)item["UpAnnouncement"].Controls[0]; 
                btn.Visible = false;         
            } 
        }       
    } 

Could you provide some more detail about your scenario if this does not help?

-Shinu.
0
James O'Brien
Top achievements
Rank 1
answered on 27 Apr 2010, 02:33 PM
If I have more then one button in a row, it fails.

aspx:
<telerik:GridButtonColumn UniqueName="UpAnnouncement" ButtonType="LinkButton" Text="xxx" />  
<telerik:GridButtonColumn UniqueName="WhichEverButton" ButtonType="LinkButton" Text="xxx" />  
<telerik:GridButtonColumn UniqueName="WhatEverButton" ButtonType="LinkButton" Text="xxx" />  

cs:
protected void RadGrid_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)  
    {  
        if (e.Item is GridDataItem)  
        {  
            foreach (GridDataItem item in gridAnnouncements.MasterTableView.Items)  
            {  
                if (item.ItemIndex == 0)  
                {  
                    LinkButton btn = (LinkButton)item["UpAnnouncement"].Controls[0];  
                    btn.Visible = false;  
                    item.Display = false;  
                    break; //terminates the for loop  
                }  
            }    
        }  
    } 

It will fail when the other buttons pass through. Is there a way of saying: if item.Name == "UpAnnouncement" or something like that?





Tags
Grid
Asked by
James O'Brien
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
James O'Brien
Top achievements
Rank 1
Share this question
or