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

RadGrid ItemCommand event and IsItemInserted

4 Answers 460 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tigger Tag
Top achievements
Rank 1
Tigger Tag asked on 14 Sep 2011, 10:47 PM
Hi,

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

4 Answers, 1 is accepted

Sort by
0
Tigger Tag
Top achievements
Rank 1
answered on 15 Sep 2011, 08:56 PM
Could anyone help me with this please!!
0
Tigger Tag
Top achievements
Rank 1
answered on 16 Sep 2011, 04:58 PM
Anyone???
0
Accepted
Mira
Telerik team
answered on 20 Sep 2011, 08:15 AM
Hello Tigger Tag,

In order to implement the desired functionality, I suggest that you fire the InitInsert command instead of setting the IsItemInserted property to true.
Please examine this help topic for additional information.

I hope this helps.

All the best,
Mira
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Tigger Tag
Top achievements
Rank 1
answered on 22 Sep 2011, 07:41 PM
Thank you Mira!! It worked like a charm, it didn't even need a call for rebind.
Tags
Grid
Asked by
Tigger Tag
Top achievements
Rank 1
Answers by
Tigger Tag
Top achievements
Rank 1
Mira
Telerik team
Share this question
or