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

RadGrid Edit Mode Insert Next/New

3 Answers 71 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 28 Feb 2014, 02:55 PM
Hi All,

The Users would like to be able to insert new records "back-to-back."  Right now they click on "Add new record," fill in their data, click on "Insert" and have to repeat that process.  They would like the addition of another button, next to "Insert," that allows for a new records to be added immediately after the current one.  Essentially, the current record would be entered, the fields would be cleared and the RadGrid would remain in EditMode.  Is this at all possible?

Thanks,
Mark

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 03 Mar 2014, 05:31 AM
Hi Mark,

Please take a look at the below code snippet. I have added a LinkButton Next in the insert form that inserts the value and keeps the insert form open for next insert.

C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditFormInsertItem && e.Item.OwnerTableView.IsItemInserted)
    {
        GridEditFormInsertItem insert = (GridEditFormInsertItem)e.Item;
        LinkButton linkButton = new LinkButton();
        linkButton.Text = "Next";
        linkButton.CommandName = "Next";
        LinkButton cancel = e.Item.FindControl("CancelButton") as LinkButton;
        cancel.Parent.Controls.Add(new LiteralControl(" "));
        cancel.Parent.Controls.Add(linkButton);
    }
}
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == "Next")
    {
        GridEditableItem edit = (GridEditableItem)e.Item;
        TextBox txt = (TextBox)edit["ColumnUniqueName"].Controls[0];
        //Code to insert to DB
        RadGrid1.MasterTableView.IsItemInserted = true;
        RadGrid1.Rebind();
    }
}

Thanks,
Princy
0
Mark
Top achievements
Rank 1
answered on 04 Mar 2014, 03:07 PM
Princy,

Thanks for the response!  I am little confused though with what is happening in these two lines:

GridEditableItem edit = (GridEditableItem)e.Item;
TextBox txt = (TextBox)edit["ColumnUniqueName"].Controls[0];

Do I have to do that for all the fields that are being edited?

Thanks,
Mark
0
Princy
Top achievements
Rank 2
answered on 05 Mar 2014, 04:07 AM
Hi Mark,

The line "GridEditableItem edit = (GridEditableItem)e.Item" is used to access the edit items of the Grid.
"TextBox txt = (TextBox)edit["ColumnUniqueName"].Controls[0]" can be used to access a particular row value in edit mode. This code was shown so that during the Next LinkButton click, you need to save the value to DB and open the form again for insert.

Suppose I have a column as shown below:
<telerik:GridBoundColumn UniqueName="OrderID" DataField="OrderID" HeaderText="OrderID">
</telerik:GridBoundColumn>

In the Insert mode I want to access this value of the column, to save to DB, I can use the following code:
GridEditableItem edit = (GridEditableItem)e.Item;
TextBox txt = (TextBox)edit["OrderID"].Controls[0]; // Get the TextBox in edit mode for the OrderID column
string id=txt.Text; // Gets the entered value in the TextBox

In-case you are doing manual CRUD operations and want to access the columns in code behind, you have to access as shown above.

I hope I made it clear to you, please let me know if any concern.
Thanks,
Princy
Tags
Grid
Asked by
Mark
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Mark
Top achievements
Rank 1
Share this question
or