Dsiable edit option in radgrid except for first row

13 posts, 2 answers
  1. Dorababu
    Dorababu avatar
    95 posts
    Member since:
    May 2012

    Posted 06 Jul 2012 Link to this post

    Hi all how can I disable edit option in radgrid. I would like to disable edit option for all the rows except first row. I would like to hide the edit icon or I would like to show alert as you can edit the old record 

    My design is as follows for edit icon

    <telerik:GridEditCommandColumn ButtonType="ImageButton" EditImageUrl="images/Edit.gif"
                        UniqueName="EmpID" />
  2. Answer
    Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 06 Jul 2012 Link to this post

    Hello,

    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
       {
           if (e.Item is GridDataItem)
           {
               GridDataItem item = e.Item as GridDataItem;
               if (item.ItemIndex == 0)
               {
                   item["EmpID"].Visible = false;
               }
           }
       }


    Thanks,
    Jayesh Goyani
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Dorababu
    Dorababu avatar
    95 posts
    Member since:
    May 2012

    Posted 06 Jul 2012 Link to this post

    Didn't worked ..
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 06 Jul 2012 Link to this post

    Hi Dorababu,

    Try the following code snippet to achieve your scenario.

    C#:
    protected void radgrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                GridDataItem item = e.Item as GridDataItem;
                if (item.ItemIndex != 0)
                {
                    item["EmpID"].Enabled = false;
                }
                else
                {
                    item["EmpID"].Enabled = true;
                }
            }
        }

    Hope this helps.

    Thanks,
    Princy.
  6. Dorababu
    Dorababu avatar
    95 posts
    Member since:
    May 2012

    Posted 06 Jul 2012 Link to this post

    I tried this which disable the selection of edit if it is not first row, but as per your given code I am unable to hide the edit image 

    protected void RadGrid2_PreRender(object sender, EventArgs e)
        {
            foreach (GridDataItem item in RadGrid2.MasterTableView.Items)
            {
                if (item.ItemIndex == 0)
                {
                    item.Enabled = true;
                }
                else
                {
                    item.Enabled = false;
                }
            }
        }
  7. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 06 Jul 2012 Link to this post

    Hi Dorababu,

    Try the following code snippet to hide the edit icon.

    C#:
    protected void radgrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                GridDataItem item = e.Item as GridDataItem;
                if (item.ItemIndex != 0)
                {
                    item["EmpID"].Visible = false;
                }
                else
                {
                    item["EmpID"].Visible = true;
                }
            }
        }

    Hope this helps.

    Thanks,
    Princy.
  8. Dorababu
    Dorababu avatar
    95 posts
    Member since:
    May 2012

    Posted 06 Jul 2012 Link to this post

    Didn't work princy
  9. Dorababu
    Dorababu avatar
    95 posts
    Member since:
    May 2012

    Posted 06 Jul 2012 Link to this post

    Changing the unique name of the control gives me the solution as per you suggested, is it possible to assign image at that place where we are setting the visibility to false
  10. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 19 Jul 2012 Link to this post

    Hi Dorababu,

    I guess you want to show image in the rows where edit buttons visibility is set false.

    C#:
    protected void Radgrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {
            GridDataItem item = e.Item as GridDataItem;
            if (item.ItemIndex != 0)
            {
                ImageButton btn = (ImageButton)item["EmpID"].Controls[0];  
                btn.ImageUrl = "Images/index.jpg";
                btn.Enabled = false;    
            }
            else
            {
                ImageButton btn = (ImageButton)item["EmpID"].Controls[0];
                btn.Visible = true;
            }
        }
    }

    Thanks,
    Princy.
  11. Stacy
    Stacy avatar
    98 posts
    Member since:
    Dec 2010

    Posted 30 Apr 2015 in reply to Princy Link to this post

    I am doing the same thing, except I want to not show the edit/delete on the first row but allow it on every other row.  I've altered the code to do this.  However, because the images are being hidden, it's throwing my first column value into where the "edit" icon would be, and my second column value into the first, etc, throwing off the alignment.  Is there a way to hide the "edit" and keep the grid aligned?
  12. Stacy
    Stacy avatar
    98 posts
    Member since:
    Dec 2010

    Posted 30 Apr 2015 in reply to Stacy Link to this post

    I manged to solve this using:

     item["editButton"].Text = "";

    This will hide the edit image I was showing and still keep the grid columns aligned.

  13. Stacy
    Stacy avatar
    98 posts
    Member since:
    Dec 2010

    Posted 30 Apr 2015 in reply to Stacy Link to this post

    Actually, my last post does keep things in line but once u hit edit on another row, you get an exception thrown.  Wish you could just hide the image and it'd be that easy.
  14. Stacy
    Stacy avatar
    98 posts
    Member since:
    Dec 2010

    Posted 30 Apr 2015 in reply to Stacy Link to this post

    this finally worked for me:

    if (e.Item is GridDataItem)
    {
        GridDataItem item = e.Item as GridDataItem;
        if (item.ItemIndex == 0)
        {
            if (item.ItemIndex == 0)
            {
                ImageButton editButton = (ImageButton)item["editButton"].Controls[0];
                editButton.Visible = false;
                ImageButton deleteButton = (ImageButton)item["deleteButton"].Controls[0];
                deleteButton.Visible = false;
            }
        }
    }
     
    if (e.Item is GridDataItem)
               {
                   GridDataItem item = e.Item as GridDataItem;
                   if (item.ItemIndex == 0)
                   {
                       if (item.ItemIndex == 0)
                       {
                           ImageButton editButton = (ImageButton)item["editButton"].Controls[0];
                           editButton.Visible = false;
                           ImageButton deleteButton = (ImageButton)item["deleteButton"].Controls[0];
                           deleteButton.Visible = false;
                       }
                   }
               }

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017