Close when Edit / Insert is finished

5 posts, 0 answers
  1. Brian Roy
    Brian Roy avatar
    4 posts
    Member since:
    Oct 2007

    Posted 22 Sep 2009 Link to this post

      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

     

  2. Todd Anglin
    Todd Anglin avatar
    2040 posts
    Member since:
    Aug 2005

    Posted 22 Sep 2009 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Echarbeneau
    Echarbeneau avatar
    21 posts
    Member since:
    Nov 2006

    Posted 25 Sep 2009 Link to this post

    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.
  5. Brian Roy
    Brian Roy avatar
    4 posts
    Member since:
    Oct 2007

    Posted 25 Sep 2009 Link to this post

    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" 
  6. Echarbeneau
    Echarbeneau avatar
    21 posts
    Member since:
    Nov 2006

    Posted 29 Sep 2009 Link to this post

    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.

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017