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

Disable Add Button in CommandItemTemplate.

3 Answers 391 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Swapna M
Top achievements
Rank 1
Swapna M asked on 20 Apr 2010, 02:10 PM
Hi,
    I have a radgrid with command item template.

 

This template has Add Icon and Delete Icon.
I want to make Add icon to be disabled/invisible in certain conditions.
How can we achieve this from code-behind?


Thanks.

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 20 Apr 2010, 04:06 PM
Hello Swapna,

It is easy to achieve this:
<asp:Button
    ID="Button1"
    runat="server"
    Visible="<%# DateTime.Now.Day == 20 %>" />

Online demo:
Command Item

Best regards,
Daniel
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Swapna M
Top achievements
Rank 1
answered on 21 Apr 2010, 10:52 AM
Hi Daniel,
    Thanks for your reply. I tried the above approach. It works fine.
But i want to do this from code-behind.
    I tried finding the control and made visible=false as shown below. It doesn't seem to work.

 

LinkButton lnkInsert = FindControlRecursive("lnkInsertRow", radGridActionDetails.MasterTableView) as LinkButton;

 

lnkInsert.Visible =

false;

 



Thanks.

0
Shinu
Top achievements
Rank 2
answered on 21 Apr 2010, 12:25 PM
Hello Swapna,

Try the  following code in order to hide the LinkButton placed in CommandItemTemplate, from code behind.

C#:
 
    protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
        if (e.Item is GridCommandItem) 
        { 
            if (condition) // Check for the condition 
            { 
                GridCommandItem cmditem = (GridCommandItem)e.Item; 
                LinkButton lbtnadd = (LinkButton)cmditem.FindControl("LinkButton1"); 
                lbtnadd.Visible = false
            } 
        } 
     } 

Regards,
Shinu.



Tags
Grid
Asked by
Swapna M
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Swapna M
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or