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

[Solved] Editform doesn't close after inserting new record

3 Answers 289 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mydatafactory
Top achievements
Rank 1
Mydatafactory asked on 19 Jun 2008, 09:39 AM
My grid displays 3 columns. When inserting a new record, the editform doesn't close automatically, but when I click the 'Cancel-button' the record has been added to the grid. What's wrong/missing in my code?

   Protected Sub gvTask_InsertCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles gvTask.InsertCommand  
        If IsValid Then  
            Dim SoortBewerking As TextBox = TryCast(e.Item.FindControl("txtSoortBewerking"), TextBox)  
            Dim status As CheckBox = TryCast(e.Item.FindControl("chkStatus"), CheckBox)  
            Dim Icon As RadComboBox = TryCast(e.Item.FindControl("cmbIcons"), RadComboBox)  
            InsertDb(SoortBewerking.Text, status.Checked = True, Int32.Parse(Icon.SelectedValue))  
 
        End If  
    End Sub  
    Private Sub InsertDb(ByVal SoortBewerking As String, ByVal Status As Boolean, ByVal Icon As Integer)  
        Dim strSQL As String = _ 
                    "INSERT INTO tblBewerkingen " & _  
                    "(soortbewerking, status, IconId) " & _  
                    "VALUES " & _  
                    "(@soortbewerking, @status, @IconId)"  
        Dim Command As New SqlCommand(strSQL)  
 
        Command.Parameters.AddWithValue("@SoortBewerking", SoortBewerking)  
        Command.Parameters.AddWithValue("@Status", Status)  
        Command.Parameters.AddWithValue("@IconId", Icon)  
 
 
        DBPortal.Execute(Command)  
 
 
    End Sub 

    <Columns> 
        <telerik:GridBoundColumn DataField="BewerkingId" DataType="System.Int32"   
            HeaderText="BewerkingId" ReadOnly="True" SortExpression="BewerkingId"   
            UniqueName="BewerkingId" Visible="False">  
        </telerik:GridBoundColumn> 
        <telerik:GridTemplateColumn HeaderText="Taak"   
            SortExpression="SoortBewerking" UniqueName="SoortBewerking">  
            <ItemTemplate> 
            <asp:Label runat="server" ID="lblSoortBewerking" Text='<%#Eval("SoortBewerking") %>'></asp:Label> 
            </ItemTemplate> 
            <EditItemTemplate> 
            <asp:TextBox runat="server" Width="100px" ID="txtSoortBewerking" Text='<%#Bind("SoortBewerking") %>'></asp:TextBox> 
            </EditItemTemplate> 
         </telerik:GridTemplateColumn> 
         <telerik:GridTemplateColumn HeaderText="Active"   
            SortExpression="Status" UniqueName="Status">  
            <ItemTemplate> 
            <asp:CheckBox runat="server" ID="chkStatus" Text='<%#Eval("Status") %>' /> 
            </ItemTemplate> 
            <EditItemTemplate> 
            <asp:CheckBox runat="server" ID="chkStatus" Text='<%#Bind("Status") %>' /> 
            </EditItemTemplate> 
            </telerik:GridTemplateColumn> 
        <telerik:GridTemplateColumn> 
                            <ItemTemplate> 
                            <asp:Image runat="server" ID="Icon"   
                                                    ImageUrl='<%# "~/Images/"+DataBinder.Eval(Container.DataItem, "Icon") %>' /> 
                            </ItemTemplate>   
                            <EditItemTemplate> 
                                <telerik:RadComboBox ID="cmbIcons" runat="server" DataSourceID="dsIcons"   
                                    DataValueField="IconId" DataTextField="IconName" AllowCustomText="false" HighlightTemplatedItems="true"   
                                    Skin="Office2007" SelectedValue='<%#Bind("IconId") %>' Text="Select a icon">  
                                    <CollapseAnimation Duration="200" Type="OutQuint" /> 
                                    <HeaderTemplate> 
                                    <table width="400px" border="0">  
                                    <tr> 
                                    <td width="30px"></td> 
                                    <td width="100px">Name</td> 
                                    </tr> 
                                    </table> 
                                    </HeaderTemplate> 
                                          <ItemTemplate> 
                                        <table style="border-bottom: 1px dotted #EFEFEF; margin-bottom: 10px; font-size: 11px;" 
                                            width="98%">  
                                            <tr> 
                                                <td> 
                                                <asp:Image runat="server" ID="Icon" 
                                                    ImageUrl='<%# "~/Images/"+DataBinder.Eval(Container.DataItem, "Icon") %>' /> 
                                                </td> 
                                                <td> 
                                                    ImageUrl='<%# "~/Images/"+DataBinder.Eval(Container.DataItem, "Icon") %>' /> 
 
                                                </td> 
                                            </tr> 
                                        </table> 
                                    </ItemTemplate> 
                                    <Items><telerik:RadComboBoxItem Selected="true" runat="server"/></Items> 
                                </telerik:RadComboBox> 
                            </EditItemTemplate>         
        </telerik:GridTemplateColumn> 
 
        <telerik:GridEditCommandColumn ButtonType="ImageButton">  
        <headerstyle width="20px" /> 
        </telerik:GridEditCommandColumn> 
        <telerik:GridButtonColumn ConfirmText="Delete this task?" ButtonType="ImageButton" CommandName="Delete" Text="Delete" UniqueName="DeleteColumn">  
        <HeaderStyle Width="20px" /> 
        </telerik:GridButtonColumn> 
    </Columns> 
 
<EditFormSettings ColumnNumber="2" CaptionDataField="SoortBewerking" CaptionFormatString="Edit properties">  
<PopUpSettings ScrollBars="None"></PopUpSettings> 
<FormTableItemStyle Wrap="false" VerticalAlign="Top" /> 
<FormMainTableStyle GridLines="Horizontal" CellPadding="3" CellSpacing="0" BackColor="#FFFFCC" Width="100%" /> 
<FormTableStyle CellSpacing="0" CellPadding="2" Width="50px" Height="50px" BackColor="#FFFFCC" HorizontalAlign="NotSet" /> 
<FormTableAlternatingItemStyle Wrap="false" VerticalAlign="Top" /> 
<EditColumn ButtonType="ImageButton" InsertText="Insert Task" UpdateText="Update Task" UniqueName="EditCommandColumn1" CancelText="Cancel Edit"></EditColumn> 
<FormTableButtonRowStyle HorizontalAlign="Right" /> 
</EditFormSettings> 
</MasterTableView> 
    </telerik:RadGrid> 
    <asp:SqlDataSource ID="dsTask" runat="server"   
        ConnectionString="<%$ ConnectionStrings:DBPortal %>"   
        DeleteCommand="DELETE FROM [tblBewerkingen] WHERE [BewerkingId] = @original_BewerkingId"   
        InsertCommand="INSERT INTO [tblBewerkingen] ([SoortBewerking], [Status], [IcondId]) VALUES (@SoortBewerking, @Status, @IconId)"   
        SelectCommand="SELECT tblBewerkingen.BewerkingId, tblBewerkingen.SoortBewerking, tblBewerkingen.Status, tblIcons.Icon, tblBewerkingen.IconId FROM tblBewerkingen LEFT OUTER JOIN tblIcons ON tblBewerkingen.IconId = tblIcons.IconId"   
        UpdateCommand="UPDATE [tblBewerkingen] SET [SoortBewerking] = @SoortBewerking, [Status] = @Status, [IconId] = @IconId WHERE [BewerkingId] = @original_BewerkingId AND [SoortBewerking] = @original_SoortBewerking AND [Status] = @original_Status AND [IconId] = @original_IconId"   
                ConflictDetection="CompareAllValues"   
        OldValuesParameterFormatString="original_{0}">  
        <DeleteParameters> 
            <asp:Parameter Name="BewerkingId" Type="Int32" /> 
        </DeleteParameters> 
        <UpdateParameters> 
            <asp:Parameter Name="SoortBewerking" Type="String" /> 
            <asp:Parameter Name="Status" Type="Boolean" /> 
            <asp:Parameter Name="IconId" Type="Int32"/>  
            <asp:Parameter Name="original_BewerkingId" Type="Int32" /> 
            <asp:Parameter Name="original_SoortBewerking" Type="String" /> 
            <asp:Parameter Name="original_Status" Type="Boolean" /> 
            <asp:Parameter Name="original_IconId" Type="Int32" /> 
        </UpdateParameters> 
        <InsertParameters> 
            <asp:Parameter Name="SoortBewerking" Type="String" /> 
            <asp:Parameter Name="Status" Type="Boolean" /> 
            <asp:Parameter Name="IconId" Type="Int32" /> 
        </InsertParameters> 
    </asp:SqlDataSource> 
    <asp:SqlDataSource ID="dsIcons" runat="server"   
        ConnectionString="<%$ ConnectionStrings:DBPortal %>"   
        SelectCommand="SELECT * FROM [tblIcons]">  
    </asp:SqlDataSource> 

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 19 Jun 2008, 10:09 AM

Hello,

Try the following line of code in the InsertCommand event to close the Insertform on clicking the Insert button.

CS:

 protected void RadGrid1_InsertCommand(object source, GridCommandEventArgs e)  
    {  
          //Code for Insert    
        e.Item.OwnerTableView.IsItemInserted = false;  
    } 


Thanks
Princy
0
Mydatafactory
Top achievements
Rank 1
answered on 19 Jun 2008, 10:54 AM

I discovered there is bugs in my code which might cause the problem. The strange thing is that the e.exception.message of  the event below not appears and that the record has been added when I click the 'Cancel-button'.

I think the bug is in the InsertCommand, but I cannot discover what the right syntax must be:
InsertDb(SoortBewerking.Text, status.Checked = True, Int32.Parse(Icon.SelectedValue))  

  • status.Checked = True 'status.Checked' is not declared or the module containing it is not loaded in the debugging session. 
  • Int32.Parse(Icon.SelectedValue) 'SelectedValue' is not a member of 'Icon'. 
    Protected Sub gvTask_ItemInserted(ByVal source As Object, ByVal e As Telerik.Web.UI.GridInsertedEventArgs) Handles gvTask.ItemInserted  
        If Not e.Exception Is Nothing Then  
            e.KeepInInsertMode = True 
            e.ExceptionHandled = True 
            SetMessage("Task cannot be inserted. Reason: " + e.Exception.Message)  
        Else  
            SetMessage("Task inserted")  
 
        End If  
 
    End Sub  
 
0
Yavor
Telerik team
answered on 19 Jun 2008, 11:38 AM
Hello A.,

Basically, if an insert/edit form does not close after update/insert, this is a sign that there is a problem with the functionality - for example, you have enabled automatic operations for the contrl, but are manually updating the underlying datasource. If the issue persists, you can open a formal support ticket, and send us a small working project, which we can review locally.

Best wishes,
Yavor
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Grid
Asked by
Mydatafactory
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Mydatafactory
Top achievements
Rank 1
Yavor
Telerik team
Share this question
or