Detect if grid is in edit mode

4 posts, 0 answers
  1. Erik
    Erik avatar
    24 posts
    Member since:
    Sep 2013

    Posted 03 Jun 2014 Link to this post

    I would like to find out in the ItemCreated event if one of the rows in the grid is in edit mode.

    I am using InPlace editing and I would like to prevent the user from clicking one of the other commands in rows that are not in edit mode.
    Also I need to disable some other fields in my form if the user is editing an item.
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 03 Jun 2014 in reply to Erik Link to this post

    Hi Erik,

    I guess you want to have only one row to be edited at a time. You can set  AllowMultiRowEdit="false". If you want to cancel any other commands you can use ItemCommand event and check the commands and cancel them. Check this article which shows how to allow either Insert or Edit at a time. Elaborate on your requirement if this doesn't help.

    Thanks,
    Princy
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Erik
    Erik avatar
    24 posts
    Member since:
    Sep 2013

    Posted 03 Jun 2014 in reply to Princy Link to this post

    Hi Princy, 

    I also need to disable some other controls on my form (which are not part of the grid). So I just need to know if one of the items is in edit mode.
    MultiRowEdit does not disable any command buttons of other rows (I added some extra command buttons).

    I can see in the ItemCommand callback that the user clicked "edit" but this event comes AFTER the ItemCreated event so this is too late for setting enabled/visibility of items in the grid.
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 04 Jun 2014 in reply to Erik Link to this post

    Hi Erik,

    I'm not clear about your requirements. I guess you have other ButtonColumns in your grid and you want to disable it when the grid is in edit mode. Please try the following code snippet. If neccessary provide your code snippet.

    ASPX:
    <telerik:GridButtonColumn CommandName="Select" Text="Select" ButtonType="LinkButton" UniqueName="ButtonColumn">
    </telerik:GridButtonColumn>

    C#:
    protected void RadGrid1_PreRender(object sender, EventArgs e)
    {
    //Checks if in edit mode
        if (RadGrid1.EditItems.Count > 0)
        {
            foreach (GridDataItem dataItem in RadGrid1.Items)
            {
               //Access the button
                LinkButton lnkbtn = (LinkButton)dataItem["ButtonColumn"].Controls[0];
                lnkbtn.Enabled = false;          
            }
        }
    }

    Thanks,
    Princy
Back to Top