Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > Beta Forum > RadGrid - Hide AddNew

Answered RadGrid - Hide AddNew

Feed from this thread
  • Henrique Duarte Intermediate avatar

    Posted on Mar 28, 2008 (permalink)

    Guys,

    Until 2007.Q3 was possible to use the default CommandItem and hide the buttons just using the code:

    protected void grid_ItemDataBound(object sender, GridItemEventArgs e) 
        if (e.Item is GridCommandItem) 
        { 
            LinkButton addButton = e.Item.Controls[0].Controls[0].Controls[0].Controls[0].Controls[0] as LinkButton; 
            addButton.Visible = false
        } 

    With 2008.Q1 "Futures", the code cannot find the button.

    Some ideas?

    []'s!

    Henrique

    Reply

  • Sebastian Sebastian admin's avatar

    Posted on Mar 28, 2008 (permalink)

    Hello Henrique,

    We introduced an easier method to get access to the buttons inside the default command item, namely by calling the FindControl(id) method (passing the id of the corresponding button). We think that this is more elegant approach than referencing items from the Controls collection of the command row elements (going several levels deeper).

    Greetings,
    Stephen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center

    Reply

  • Henrique Duarte Intermediate avatar

    Posted on Mar 28, 2008 (permalink)

    Hi Stephen!

    Thanks for your quick response!

    I tried the code:

    protected void grid_ItemDataBound(object sender, GridItemEventArgs e) 
        if (e.Item is GridCommandItem) 
        { 
            LinkButton addButton = e.Item.FindControl("InitInsertButton"as LinkButton; 
            addButton.Visible = false
        } 
     

    But addButton is null.

    Am I doing it right?

    []'s!

    Henrique

    Reply

  • Sebastian Sebastian admin's avatar

    Posted on Mar 28, 2008 (permalink)

    Hello Henrique,

    Try the following code modification:

    protected void grid_ItemDataBound(object sender, GridItemEventArgs e)    
    {    
        if (e.Item is GridCommandItem)    
        {    
            ImageButton addButton = e.Item.FindControl("InitInsertButton"as ImageButton;    
            addButton.Visible = false;    
        }    
    }    
     

    Best regards,
    Stephen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center

    Reply

  • Henrique Duarte Intermediate avatar

    Posted on Mar 28, 2008 (permalink)

    Hi Stephen!

    Your code doesn't even compile.
    You're trying to pass a ImageButton to a LinkButton, but is not the case.
    The method FindControl returns NULL.
    Insert a breakpoint and you'll see.

    e.Item.FindControl("InitInsertButton") == null !!!

    Thanks again for your quick response.

    []'s!

    Henrique

    PS: I've requested a feature and now I'm just posting it in a public forum:

    Add two attributes for tag "CommandItemSettings":
    • AddNewVisible
    • RefreshVisible
    I don't want to change the Command style or create a new template. I want to use yours template but sometimes, don't want to use one of the buttons.

    Would be nice if we have these two attributes! (less code for us)

    Thanks again!

    Reply

  • Answer Sebastian Sebastian admin's avatar

    Posted on Mar 28, 2008 (permalink)

    Hello Henrique,

    I apologize for the mistake I made in my previous post. Actually you need to cast the [Add new record] button to Button instead of ImageButton, namely:

    protected void grid_ItemCreated(object sender, GridItemEventArgs e)       
    {       
        if (e.Item is GridCommandItem)       
        {       
            Button addButton = e.Item.FindControl("InitInsertButton"as Button;       
            addButton.Visible = false;       
        }       
    }     
     

    This is due to the new rendering of the default grid images (rendered with img tags) which are now part of sprites. We plan to add a separate topic in the grid online documentation elaborating on this matter for the official Q1 2008 release, scheduled in the middle of April.

    Best regards,
    Stephen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center

    Reply

  • Henrique Duarte Intermediate avatar

    Posted on Mar 28, 2008 (permalink)

    Stephen,

    Just one more thing.
    The text set on attributes are not appearing.

    []'s

    Henrique

    Reply

  • Sebastian Sebastian admin's avatar

    Posted on Mar 28, 2008 (permalink)

    Hi Henrique,

    The text for the [Add new record]/[Refresh] buttons in the command item will appear as tooltip when you hover the relevant button. Do you consider this change appropriate or prefer to have the previous text message side by side with the button? We may consider reverting back the old behavior (having text beside the button) for the official Q1 2008 release.

    Best regards,
    Stephen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center

    Reply

  • Henrique Duarte Intermediate avatar

    Posted on Mar 28, 2008 (permalink)

    Stephen,

    I don't know how users are there, but here in Brazil ... some of them are so dumb that sometimes we need the text.
    Just a suggestion, you can leave the old behavior and if we don't want the text, just set the attribute "AddNewRecordText" or "RefreshText" to empty (""). Another consideration, is to add two attributes "AddNewRecordToolTip" and "RefreshToolTip" like the validators have: a text for a tooltip, a text for span and another one for javascript.

    OK!?

    I know that is a "big" change, but I'm helping you to keep your job!!
    =D

    []'s!

    Henrique

    Reply

  • Sebastian Sebastian admin's avatar

    Posted on Mar 28, 2008 (permalink)

    Hi Henrique,

    I spoke with our grid developers and they stated that the old behavior (text beside the command item buttons) will be reverted for the Q1 2008 of RadControls Prometheus. I believe this is good news for you. Thank you for sharing your opinion on this subject.

    Best regards,
    Stephen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center

    Reply

  • Henrique Duarte Intermediate avatar

    Posted on Mar 28, 2008 (permalink)

    Stephen,

    Just more one question, I swear!
    Will you keep this code working on next version?

    Button addButton = e.Item.FindControl("InitInsertButton"as Button; 

    Thanks again!

    Henrique

    Reply

  • Sebastian Sebastian admin's avatar

    Posted on Mar 31, 2008 (permalink)

    Hello Henrique,

    Yes, this code will be operational with the official version of RadGrid Prometheus, too.

    Best regards,
    Stephen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center

    Reply

  • Christian Surieux Master avatar

    Posted on Jun 2, 2008 (permalink)

    Hi Stephen,

    using your code with Rad for Ajax Q1 2008
                    Control btn = e.Item.FindControl("InitInsertButton");
                    btn.Visible = false;

    only hides the button, the image is still diplayed, how to to hide it ?

    Thanks CS

    Reply

  • Dimo Dimo admin's avatar

    Posted on Jun 3, 2008 (permalink)

    Hi Christian,

    As of Q1 2008 the "Add New" button in the command item consists of two buttons. This is skinning optimization purposes.

    In order to hide both buttons (image and link), please use:

    protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) 
        if (e.Item is GridCommandItem) 
        { 
            Button spriteAddButton = e.Item.FindControl("AddNewRecordButton"as Button; 
            spriteAddButton.Visible = false
     
            LinkButton addButton = e.Item.FindControl("InitInsertButton"as LinkButton; 
            addButton.Visible = false
        } 


    Regards,
    Dimo
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center

    Reply

  • Christian Surieux Master avatar

    Posted on Jun 3, 2008 (permalink)

    Thanks
    CS

    Reply

  • karen healey avatar

    Posted on Mar 24, 2009 (permalink)

    How do you hook this up in the ASPX page?

    Reply

  • karen healey avatar

    Posted on Mar 24, 2009 (permalink)

    Never mind, I found it, the "OnItemCreated" even for the RadGrid control, like so:

    <telerik:RadGrid ID="RadGrid1" runat="server" OnItemCreated="grid_ItemCreated">

    Reply

  • Kavi avatar

    Posted on Aug 4, 2009 (permalink)

    Hi,
    I'm using Q2- 2009. How do i add a tooltip to the "Refresh" button in the grid..

     

     

     

     

     

    if (e.Item is GridCommandItem)  
                    {  
                        ((LinkButton)e.Item.FindControl("InitInsertButton")).ToolTip = "Click here to add new record";  
                    } 

     
    this worked for the "Add new record" button.  Please help me in providing a tooltip for the "Refresh" button.

    Thanks.

     

    Reply

  • Sebastian Sebastian admin's avatar

    Posted on Aug 4, 2009 (permalink)

    Hello dinesh,

    The id of the default refresh button in the command item is RebindGridButton as explained in this topic. Hence using this code inside the ItemCreated server handler of the grid should do the trick:

    if (e.Item is GridCommandItem)     
                    {     
                        ((LinkButton)e.Item.FindControl("RebindGridButton")).ToolTip = "Click here to refresh the grid";     
                    }    
     

    Best,
    Sebastian
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.

    Reply

  • Cads avatar

    Posted on Jan 27, 2010 (permalink)

    This seem to work for me:

            protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)  
            {  
                //Hides the Add New Record option in the header  
                if (e.Item is GridCommandItem)  
                {  
                    e.Item.FindControl("AddNewRecordButton").Visible = false;  
                    e.Item.FindControl("InitInsertButton").Visible = false;  
                }  
            } 

     

    I wired this up with OnItemCreated="RadGrid1_ItemCreated" in the RadGrid object.

    Reply

  • Matt Dell avatar

    Posted on May 28, 2010 (permalink)

    EDIT: Figured it out!  Updated below in bold.

    Ok, I have the following

    protected void PhoneBook_ItemCreated(object sender, GridItemEventArgs e) 
            { 
                //Hides the Add New Record / Refresh option in the header   
                if (e.Item is GridCommandItem) 
                { 
                    e.Item.FindControl("AddNewRecordButton").Visible = false
                    e.Item.FindControl("InitInsertButton").Visible = false
                    e.Item.FindControl("RebindGridButton").Visible = false
                }   
            }  

    This hides the Add New Record Button / Text and the Refresh text.  So, I've deduced...

    AddNewRecordButton = Green "+" button to Add New Record
    InitInsertButton = "Add New Record" text
    RebindGridButton = "Refresh" text
    RefreshButton = Refresh Button

    What is the control name for the refresh button so I can hide that as well?  I have referenced this topic, but it doesn't tell me what the Control ID is for the refresh button.

    Cheers,
    -Matt

    Reply

  • Manoj avatar

    Posted on Sep 10, 2010 (permalink)

    Hi Matt,
    The button which you trying to hide is not a image button it's just a button only, so try to write in this way.

    Button

     

     btn = e.Item.FindControl("RefreshButton") as Button;
    btn.Visible = false;

     

    Reply

  • rohan avatar

    Posted on Jul 5, 2011 (permalink)

    Instead of finding all the controls and hiding them, just say

    protected void PhoneBook_ItemCreated(object sender, GridItemEventArgs e)
            {
                //Hides the Add New Record / Refresh option in the header  
                if (e.Item is GridCommandItem)
                {
                      e.item.visible = false;
                }
           }

    This should do the job.

    Regards,
    Rohan Kondvilkar

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > Beta Forum > RadGrid - Hide AddNew