Update then edit next row.

4 posts, 1 answers
  1. Danny
    Danny avatar
    35 posts
    Member since:
    May 2012

    Posted 24 Jan 2013 Link to this post

    I've added another button to the standard edit template, 'Update then edit next row'.  I need to create an event that will put the next row, if it exists, into edit mode.

    protected void rgDemandForecast_OnItemCreated(object source, GridItemEventArgs e)
            {
                if (e.Item is Telerik.Web.UI.GridEditFormItem && e.Item.IsInEditMode)
                {
                    LinkButton linkButton = new LinkButton();
                    linkButton.Text = "Update And Edit Next Row";
                    linkButton.CommandName = "Update";
      
                    linkButton.Attributes["onclick"] = "some javascript";
                          //or
                    linkButton.Click += updateAndEditNextRow_OnClick;
      
                    
    LinkButton update = e.Item.FindControl("UpdateButton") as LinkButton;
                    update.Parent.Controls.Add(new LiteralControl(" "));
                    update.Parent.Controls.Add(linkButton);
                }
      
      
            }

    Can someone give me a general outline of which javascript methods i need to get the current row and then put the next row into edit mode?

    I don't mind doing this in my updateAndEditNextRow_OnClick method, but would prefer to keep this client-side.
  2. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 24 Jan 2013 Link to this post

    Hello,

    protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
       {
           if (e.CommandName == RadGrid.UpdateCommandName)
           {
             // Update logic comes here
               if (RadGrid1.MasterTableView.PageSize > e.Item.ItemIndex + 1)
               {
                   RadGrid1.MasterTableView.Items[e.Item.ItemIndex + 1].Edit = true;
               }
           }
       }


    Thanks,
    Jayesh Goyani
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 24 Jan 2013 Link to this post

    Hi,

    Try the following code to achieve your scenario.
    C#:
    protected void LinkButton1_Click(object sender, EventArgs e)
       {
           foreach (GridEditableItem item in RadGrid1.EditItems)
           {
               RadGrid1.MasterTableView.Items[item.ItemIndex + 1].Edit = true;
                    RadGrid1.Rebind();
           }
       }

    Thanks,
    Shinu
  5. Danny
    Danny avatar
    35 posts
    Member since:
    May 2012

    Posted 25 Jan 2013 Link to this post

    foreach (GridEditableItem item in rgDemandForecast.EditItems)
                {
                          int extraRowsInGrid = 2;  
                    if (item.ItemIndex + extraRowsInGrid <= rgDemandForecast.MasterTableView.Items.Count)
                    {
                        rgDemandForecast.MasterTableView.Items[item.ItemIndex + 1].Edit = true;
                        rgDemandForecast.Rebind()
                    }
                }

    Shinu, your code got it done, thanks.

    Just had to add an extra conditional to make sure we weren't at the last row, and the extraRowsInGrid to compensate for my current formatting. 

    Thanks again, Shinu.  
Back to Top