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

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

1 Answer 76 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> 

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 19 Jun 2008, 10:02 AM
Hi,

Are you binding the Grid using AdvanceDataBinding techniques?
Advanced data-binding

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