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

Close when Edit / Insert is finished

7 Answers 719 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brian Roy
Top achievements
Rank 1
Brian Roy asked on 22 Sep 2009, 11:02 PM
  No matter what i try i cant get the edit/insert form to close when i use forms or popup.

 

//this throws and error : Insert item is available only when grid is in insert mode.
protected void RadGrid1_InsertCommand(object source, Telerik.Web.UI.GridCommandEventArgs e) {   
 
e.Item.OwnerTableView.IsItemInserted = false;   
 
RadGrid1.Rebind();  
 
}  
 
//this had no effect   
 
protected void RadGrid1_InsertCommand(object source, Telerik.Web.UI.GridCommandEventArgs e) {   
 
e.Cancelled = true;  
 
RadGrid1.Rebind();  
 
}  
 
// nothing on edit either   
 
protected void RadGrid1_UpdateCommand(object source, Telerik.Web.UI.GridCommandEventArgse) {   
 
RadGrid1.MasterTableView.ClearEditItems();   
 
RadGrid1.Rebind();  
 
}  
 

// some additional background info:

I have tried it in forms & popup and with a user control and not

 

 

 

<telerik:RadGrid ID="RadGrid1" runat="server"   
 
GridLines="None"   
 
AllowPaging="True"   
 
PageSize="10"   
 
AllowAutomaticDeletes="True"   
 
AllowAutomaticInserts="True"   
 
AllowAutomaticUpdates="True"   
 
AutoGenerateColumns="False"   
 
OnItemDataBound="RadGrid1_ItemDataBound"   
 
OnInsertCommand="RadGrid1_InsertCommand"   
 
OnUpdateCommand="RadGrid1_UpdateCommand"   
 
OnDeleteCommand="RadGrid1_DeleteCommand"   
 
OnNeedDataSource="RadGrid1_NeedDataSource">   
 
<PagerStyle Mode="NextPrevAndNumeric" />   
 
<MasterTableView Width="950" CommandItemDisplay="TopAndBottom" DataKeyNames="PromoCode" EditMode="EditForms" >   
 
<Columns>   
 
<telerik:GridTemplateColumn>   
 
<ItemTemplate>   
 
<asp:ImageButton ID="Button1" runat="server" ImageUrl="~/App_Themes/Default/Images/EditButton.gif"   
 
Text="Edit" CommandName="Edit" />   
 
</ItemTemplate>   
 
</telerik:GridTemplateColumn>   
 
<telerik:GridTemplateColumn HeaderText="PromoCode" SortExpression="PromoCode" UniqueName="PromoCode">  
 
<ItemTemplate>   
 
<asp:Label runat="server" ID="lblPromoCode" Text='<%# Eval("PromoCode") %>'></asp:Label>   
 
</ItemTemplate>   
 
<EditItemTemplate>   
 
<asp:TextBox runat="server" ID="tbxPromoCode" EnableViewState="true" ></asp:TextBox>   
 
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="tbxPromoCode"   
 
ErrorMessage="*" runat="server">   
 
</asp:RequiredFieldValidator>   
 
</EditItemTemplate>   
 
</telerik:GridTemplateColumn> 
 
<telerik:GridButtonColumn ConfirmText="Delete this Item?" ConfirmDialogType="RadWindow"   
 
ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" Text="Delete"   
 
UniqueName="DeleteColumn">   
 
</telerik:GridButtonColumn>   
 
</Columns>   
 
</MasterTableView>   
 
</telerik:RadGrid>   
 
 

 

 Page.Response.Redirect does work but it is not an option. lol

 

7 Answers, 1 is accepted

Sort by
0
Todd Anglin
Top achievements
Rank 2
answered on 23 Sep 2009, 02:08 AM
Hello Brian-

Sorry to hear you're having trouble with the edit modes! Let's see if we can solve this problem.

By default, when you edit a row with RadGrid using PopUp or Forms (or even UserControl), the edit form should automatically close when you fire the Insert/Update command. For some "proof by example," check out these live demos:


That said, based on the RadGrid configuration you posted, it does not seem to be properly configured for data editing. I suggest you add a GridEditCommandColumn. This column will automatically provide the "Edit" button in the "read mode" and the "Update/Cancel" buttons in the edit mode. An example with this column can be found here:


Additionally, make sure your Page Validation is not causing problems with your data operations. I see that you've got some ASP.NET validation controls in your edit templates. If those do not validate, your grid will appear not to "exit" edit mode when the page is posted.

Give that a try and let me know if it helps.

-Todd
0
Echarbeneau
Top achievements
Rank 1
answered on 25 Sep 2009, 06:52 PM
I was having the same issue. I found that when I had started off I was using the automatic features but then later dropped them in favor of doing things manually. I had forgotten to set AllowAutomaticInserts="True" back to false. From your post I can't tell too much about what your situation is, but if this applies to you I suggest trying it.

Also, I found my solution by quickly rebuilding another grid on another page to the point where it could be tested. Then I compared the properties and noticed what was different.

Regards,
Ed C.
0
Brian Roy
Top achievements
Rank 1
answered on 25 Sep 2009, 09:09 PM
I have tried it with validation and it without validation. The GridEditCommandColumn opens it up but the Insert and Update links  are the ones that are having the issue. The problem is when you implement onInsertcommand and onUpdateCommand methods auto insert and updates must be set to false. I hammered all the possible combinations I could think of and Ed C. Was right on the money. Thanks for all your help.


//So the solution is set these to false
AllowAutomaticInserts="False"   
 
AllowAutomaticUpdates="False"   
 
 
// When you have these
 
OnInsertCommand="RadGrid1_InsertCommand"   
 
OnUpdateCommand="RadGrid1_UpdateCommand" 
0
Echarbeneau
Top achievements
Rank 1
answered on 29 Sep 2009, 06:22 PM
Thanks for reporting back, and I'm glad that my suggestion worked out for you. I burned a good hour or two with this my self and was wondering if the grid should throw some sort of error in place of this odd behavior.

0
Reginardo
Top achievements
Rank 1
answered on 06 Mar 2017, 06:02 PM
That's works for me. Thanks!
0
frederic
Top achievements
Rank 1
answered on 27 Mar 2017, 07:41 PM

You may also come across the situation if you have ajaxified your RadGrid because you are experiencing a partial postback of your page.   If you have an "OnRequestStart" RadAjaxManager event handler for your page, you can catch the event firing when you click the "Insert" button.  check the event target out to see if it is coming from your grid insertion click.

if so, you may want to set_enableAjax to false for that specific request and see if that helps.

I have something to the effect of the following and my RadGrid now successfully exits the "edit mode" of the grid.  Note that I am using a UserControl to configure the mode of the grid.

ajaxmanager

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest" >
            <ClientEvents OnRequestStart="onRequestStart" />
            <AjaxSettings>...

 

javascript

function onRequestStart(sender, args) {
   //this is the client event RadAjaxManager handles
   var eventTarget = args.get_eventTarget();
   //this is the command that can be modified before it is sent to the requester
   var eventArgs = args.get_eventArgument();
 
   if (eventTarget.indexOf("btnInsert") > -1) {
         args.set_enableAjax(false);
   }
}

.aspx (insert button)

<telerik:RadButton ID="btnInsert" runat="server" ButtonType="StandardButton" Skin="Sunset" Text='<%# Container is GridEditFormInsertItem ? "Insert" : "Update" %>' CommandArgument='<%# Container is GridEditFormInsertItem ? "PerformInsert" : "Update" %>' CommandName='<%# Container is GridEditFormInsertItem ? "PerformInsert" : "Update" %>' />

 

RadGrid definition

<telerik:RadGrid ID="AuthoritativeDataGrid"
    runat="server"
    AutoGenerateColumns="false"
    OnNeedDataSource="AuthoritativeDataGrid_NeedDataSource"
    EnableLinqExpressions="false"
    OnInsertCommand="AuthoritativeDataGrid_InsertCommand"
    OnItemDataBound="AuthoritativeDataGrid_ItemDataBound"
    OnUpdateCommand="AuthoritativeDataGrid_UpdateCommand"
    >...

 

insert handler

protected void AuthoritativeDataGrid_InsertCommand(object sender, GridCommandEventArgs e)
{
    UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);
 
    System.Data.SqlClient.SqlCommand command = _utilities.insertAuthoritativeData([inputs]);
    System.Data.DataTable results = _utilities.executeSqlCommand(command);
 
}
0
Raoul
Top achievements
Rank 1
answered on 04 Sep 2018, 03:01 PM

[quote]Echarbeneau said:I was having the same issue. I found that when I had started off I was using the automatic features but then later dropped them in favor of doing things manually. I had forgotten to set AllowAutomaticInserts="True" back to false. From your post I can't tell too much about what your situation is, but if this applies to you I suggest trying it.

Also, I found my solution by quickly rebuilding another grid on another page to the point where it could be tested. Then I compared the properties and noticed what was different.

Regards,
Ed C.
[/quote]

this has helped a ton. Thanks!

Tags
Grid
Asked by
Brian Roy
Top achievements
Rank 1
Answers by
Todd Anglin
Top achievements
Rank 2
Echarbeneau
Top achievements
Rank 1
Brian Roy
Top achievements
Rank 1
Reginardo
Top achievements
Rank 1
frederic
Top achievements
Rank 1
Raoul
Top achievements
Rank 1
Share this question
or