This is a migrated thread and some comments may be shown as answers.

Update then edit next row.

3 Answers 76 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Danny
Top achievements
Rank 2
Danny asked on 24 Jan 2013, 06:31 PM
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.

3 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 25 Jan 2013, 04:57 AM
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
0
Accepted
Shinu
Top achievements
Rank 2
answered on 25 Jan 2013, 05:06 AM
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
0
Danny
Top achievements
Rank 2
answered on 25 Jan 2013, 03:02 PM
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.  
Tags
Grid
Asked by
Danny
Top achievements
Rank 2
Answers by
Jayesh Goyani
Top achievements
Rank 2
Shinu
Top achievements
Rank 2
Danny
Top achievements
Rank 2
Share this question
or