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

When Cancel command is not closing the form template

1 Answer 173 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Civbaron
Top achievements
Rank 1
Civbaron asked on 10 Jun 2010, 06:00 PM
Hi,

I have created a radgrid that uses an editformtemplate to allow for inserts and updates to data. We are using our own code to insert data into the database and to update the data in the database. In the formtemplate we have the update button being set to different commands based on the container. We also have a cancel button in the form.

If the user is editing a record and presses the cancel button the screen will refresh and the form is gone leaving only the grid. If the user is creating a record and presses the cancel button the screen will refreash but the form is still present on the screen. Here is the code we are currently using in the itemcommand event of the radgrid:

 

protected void rgFormFields_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)

 

{

 

if (e.CommandName == "Cancel")

 

{

e.Canceled =

true;

 

rgFormFields.MasterTableView.ClearEditItems();

rgFormFields.Rebind();

}

 

else if (e.CommandName == "Update")

 

{

Update(e);

e.Canceled =

true;

 

rgFormFields.MasterTableView.ClearEditItems();

rgFormFields.Rebind();

}

 

else if (e.CommandName == "PerformInsert")

 

{

 

//bAddNewFormField_Click(source, e);

 

Insert(e);

e.Canceled =

true;

 

rgFormFields.MasterTableView.ClearEditItems();

rgFormFields.Rebind();

}

}

Anyhelp would be greatly appreciated.
Thanks,
Jonathan

1 Answer, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 11 Jun 2010, 05:32 AM
Hello Jonathan,

I am not sure about why the insertform is not closing when clicking the button with CommandName set as "Cancel". It is working fine when I tried on my end.

You can also explicitly close the insertform from code behind by setting the IsItemInserted property to false. Here is the sample code.

C#:
 
  if (e.CommandName == "Cancel"
        { 
            e.Canceled = true
            RadGrid1.MasterTableView.IsItemInserted = false
            RadGrid1.MasterTableView.ClearEditItems(); 
            RadGrid1.Rebind(); 
        } 

Regards,
Shinu.


Tags
Grid
Asked by
Civbaron
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or