I am using ajaxified RadGrid with user control for edit form. On the user edit control I need a button 'Insert & Add another' which saves the current item and openes up empty edit control to add another item to the grid. I have added InsertAnother button on the edit control and I added the code below to acheive this in ItemCommand event. I also have a code on InitInsert to set a default value for a field on the user control, also shown below. When I click InsertAnother button it does save the current item and open up the user edit control to add new item as expected but ItemCommand event is never fired for the new insert control, so default value for TextBox1 is never being set. So, my question is, am I handling the InsertAnother button event correctly? Is there a better way to do it? If the way I handled is correct, why is ItemCommand event with InitInsert command name is not firing for new insert user control. Any help is greatly appreciated.
protected
void Grid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e) {
//if IsertAnother button is clicked
if (e.CommandName == "InsertAnother") {
//insert and then set the grid to insert again to open up new item window
handleInsert(sender, e);
//if the event is not cancelled, set the grid in insert mode to insert another item and call rebind on the grid
if (!e.Canceled) {
Grid1.MasterTableView.IsItemInserted =
true;
Grid1.Rebind();
}
}
//if the user selected to do the insert
if (e.CommandName == RadGrid.InitInsertCommandName) {
e.Canceled =
true;
e.Item.OwnerTableView.InsertItem();
GridEditableItem insertedItem = e.Item.OwnerTableView.GetInsertItem();
//fidn the edit control id
String userEditControlId = GridEditFormItem.EditFormUserControlID;
//get the edit control
UserControl userEditControl = insertedItem.FindControl(userEditControlId) as UserControl;
//get the text box1
RadTextBox TxtBox = userEditControl.FindControl("TextBox1") as RadTextBox;
TxtBox.Text = "10";
}
}
Thank you,
Ana