Hide Edit Button Conditionally

2 posts, 0 answers
  1. Julie
    Julie avatar
    2 posts
    Member since:
    Jun 2012

    Posted 15 Aug 2011 Link to this post

    This is my first post so I am sorry ahead of time if this is the wrong forum.....

    I am trying to hide the edit button in a radgrid if the field LOCKED is set to 1 but it is not working - any ideas?

    Thanks
    Julie


    private void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {
            GridDataItem dataItem = e.Item as GridDataItem;
            GridEditManager manager = dataItem.EditManager;
            IGridColumnEditor editor = manager.GetColumnEditor("Locked");
            TextBox box = (editor as GridTextBoxColumnEditor).TextBoxControl;
            if (box.Text == "1")
            {
                dataItem["EditCommandColumn"].Controls[0].Visible = false;
            }
            else
            {
                dataItem["EditCommandColumn"].Controls[0].Visible = true;
            }
        }
    }
  2. Andrey
    Admin
    Andrey avatar
    836 posts

    Posted 18 Aug 2011 Link to this post

    Hi Julie,

    If I understand you right, you should do something like this:

    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                GridDataItem dataItem = e.Item as GridDataItem;
                if (dataItem["Locked"].Text == "1")
                {
                    dataItem["EditCommandColumn"].Controls[0].Visible = false;
                }
                else
                {
                    dataItem["EditCommandColumn"].Controls[0].Visible = true;
                }
            }
        }

    If that is not the case, please provide a sample project.

    Regards,
    Andrey
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Back to Top