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

How do I close Edit Template

4 Answers 148 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Steven
Top achievements
Rank 1
Steven asked on 26 Apr 2013, 11:24 AM
I have a RadGrid with NeedDataSource binding.  It also has an EditTemplate. The following code works well for saving the users updates except that the EditTemplate doesn't close. How do I close the EditTemplate?

protected void ModelGrid_UpdateCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        {
            if (e.CommandName == RadGrid.UpdateEditedCommandName)
            {
                if (e.Item is GridEditFormItem)
                {
                    GridEditFormItem item = (GridEditFormItem)e.Item;
                    string id = item.GetDataKeyValue("ModelId").ToString();
                    if (!String.IsNullOrEmpty(id))
                    {

                        Model m = new Model();
                        try
                        {
                            m.ModelId = id;
                            m.ManufacturerId = SelctedManufacturerId;
                            m.ModelNumber = ((TextBox)item.FindControl("txtEditModelNumber")).Text;
                            m.Description = ((TextBox)item.FindControl("txtEditDescription")).Text;
                            m.ProductLineId = ((RadComboBox)item.FindControl("ddlProductLine")).SelectedValue;
                            m.AssetTypeId = ((RadComboBox)item.FindControl("ddlAssetType")).SelectedValue;
                            m.DefAssetPosition = int.Parse(((DropDownList)item.FindControl("ddlDefAssetPos")).SelectedValue);

                            m.UseRackUnits = ((CheckBox)item.FindControl("chkUseRack")).Checked;
                            m.Height = (Double)((RadNumericTextBox)item.FindControl("numEditHeight")).Value;
                            m.Width = (Double)((RadNumericTextBox)item.FindControl("numEditWidth")).Value;
                            m.Depth = (Double)((RadNumericTextBox)item.FindControl("numEditDepth")).Value;

                            AssetVueBLL.UpdateModel(m, MySession.Current.UserId);
                            ModelGrid.Rebind();
                            
                        }
                        catch (Exception ex)
                        {
                            ModelGrid.Controls.Add(new LiteralControl("<strong>Unable to save Model</strong> - " + ex.Message));
                            e.Canceled = true;
                        }
                    }
                }
            }
        }

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 26 Apr 2013, 11:49 AM
Hi,

Please make sure that you are not setting the RadGrid property AllowAutomaticUpdates to true in the markup.

Thanks,
Princy
0
Steven
Top achievements
Rank 1
answered on 26 Apr 2013, 11:59 AM
I was, so I removed that property. It didn't help. 

This might be a failure to update the Ajax Update Panel I'm using.  But these controls are in the grid which is in the updatepanel, so they should trigger the update.
0
J
Top achievements
Rank 1
answered on 26 Apr 2013, 04:52 PM
You should be able to add this at the end of the event being triggered:

Client side:
$find("<%=ModelGrid.ClientID %>").get_masterTableView().clearSelectedItems();

Server side:
ModelGrid.MasterTableView.ClearEditItems();

That should clear out any items that are in edit mode and close out any edit templates/forms.
0
Tsvetoslav
Telerik team
answered on 01 May 2013, 05:49 AM
Hi Steven,

First of all do remove the call to the grid's Rebind() method from the Update command.

There reason for the edit form's staying open, however, is different. If the catch in the method is hit and the e.Canceled = true is called then the form will stay open.

Another possible cause is indeed tha ajaxification of the grid control but without looking at your code it is difficult to say what exactly goes wrong. So, please, paste your complete aspx and code behind using the CODE FORMATTER tool of the ticket editor.

Regards, Tsvetoslav
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.
Tags
Grid
Asked by
Steven
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Steven
Top achievements
Rank 1
J
Top achievements
Rank 1
Tsvetoslav
Telerik team
Share this question
or