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

[Solved] How to keep row in edit mode afetr insertcommand

3 Answers 247 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Aditi
Top achievements
Rank 1
Aditi asked on 23 Oct 2012, 12:59 AM

Hi,

I have a radgrid no my webpage. After insert or update, I want to keep grid in edit mode.
The item.edit = true, works on update command event or even from external save button. It is not working for InsertCommand event.
This is the code I am using:

protected void RadGrid1_InsertCommand(object source, GridCommandEventArgs e)
        {
            if (e.CommandName == RadGrid.PerformInsertCommandName)
            {
                if (e.Item is GridEditableItem)
                {
                    GridEditableItem item = (GridEditableItem)e.Item;
  
                    //Save Quote and get quoteid
                    this.SaveQuote();
  
                    if (this.SaveQuoteItem(item, QuoteID, true))
                    {
                        e.Canceled = true;
                        item.Edit = true;
                        RadGrid1.MasterTableView.IsItemInserted = false;
                        RadGrid1.Rebind();
                    }
                    //}
                }
            }
        }

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 25 Oct 2012, 04:21 AM
Hi,

Please try the following code snippet to make the RadGrid in edit mode after insertion.

C#:
protected void RadGrid1_InsertCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.PerformInsertCommandName)
    {
        if (e.Item is GridEditableItem)
        {
            GridEditableItem item = (GridEditableItem)e.Item;
            this.SaveQuote();
            if (this.SaveQuoteItem(item, QuoteID, true))
            {
                e.Canceled = true;
                foreach (GridDataItem ditems in RadGrid1.MasterTableView.Items)
                {
                    ditems.Edit = true;
                }
                RadGrid1.MasterTableView.IsItemInserted = false;
                RadGrid1.Rebind();
            }
        }                
    }     
}

Thanks,
Shinu.
0
Suman
Top achievements
Rank 1
answered on 19 Aug 2013, 12:55 PM
Hi Shinu..,

I am using d above code for inserting the data with in  grid  but getting errors here could u plz suggest me ASAP.

send me d code for insert data using oracle db.




Thks,

suman.
0
Shinu
Top achievements
Rank 2
answered on 20 Aug 2013, 05:07 AM
Hi Suman,

Please check the code to make the inserted row in RadGrid to edit mode.

C#:
static string lastId = string.Empty;
protected void RadGrid1_InsertCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
    if (e.Item.OwnerTableView.IsItemInserted)
    {
            GridEditableItem edit = e.Item.OwnerTableView.GetInsertItem();
            TextBox tx = (TextBox)edit["OrderID"].Controls[0];
            // your code for inserting the row to db
            // your code for getting the Last inserted OrderID from db
            //assign the Last inserted OrderID to a static sring 'lastId'            
    }                  
}
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
    if (lastId != string.Empty)
    {
        foreach (GridDataItem item in RadGrid1.Items) // accessing the rows in radgrid
        {
            if (item["OrderID"].Text == lastId)  //checking for the last inserted value
            {
                item.Edit = true;
                RadGrid1.Rebind();
            }
        }
    }
}

Thanks,
Shinu.
Tags
Grid
Asked by
Aditi
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Suman
Top achievements
Rank 1
Share this question
or