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

[Solved] Insert template won't go away

4 Answers 179 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Perry
Top achievements
Rank 1
Perry asked on 09 Dec 2009, 10:02 PM
I have a grid which uses a declaritive form template (MasterTableView->EditFormSettings=Template->FormTemplate.

The insert/update command invokes either an insert or update.

The ItemCommand function runs properly. Inserts and updates are executed.

For an update, the template disappears when processing complete.

For an insert, I can't make the template disappear.

Can you help?

4 Answers, 1 is accepted

Sort by
0
Perry
Top achievements
Rank 1
answered on 09 Dec 2009, 10:06 PM
    protected void ItemCommand(object source, GridCommandEventArgs e)  
    {  
        divError.Visible = false;  
 
        if (e.Item is GridEditFormItem && e.Item.IsInEditMode && (e.CommandName == "Insert" || e.CommandName == "Update"))  
        {  
            GridEditFormItem efi = e.Item as GridEditFormItem;  
            GridDataItem pi = efi.ParentItem;  
 
            try 
            {  
... get stuff...  
... validate stuff...  
                if (e.CommandName == "Update")  
                {  
... this all works...  
                }  
                else 
                {  
                    OdbcTransaction transaction = csconnection.BeginTransaction();  
                    OdbcCommand command = new OdbcCommand("insert into people set email=?,lastname=?,firstname=?,job=?;", csconnection);  
                    command.Parameters.AddWithValue("@email", email);  
                    command.Parameters.AddWithValue("@lastname", lastname);  
                    command.Parameters.AddWithValue("@firstname", firstname);  
                    command.Parameters.AddWithValue("@job", jobid);  
                    command.Transaction = transaction;  
                    command.ExecuteNonQuery();  
 
                    command = new OdbcCommand("insert into holidaycontributions set email=?,year=?,amount=?;", csconnection);  
                    command.Parameters.AddWithValue("@email", email);  
                    command.Parameters.AddWithValue("@year", theyear);  
                    command.Parameters.AddWithValue("@amount", a);  
                    command.Transaction = transaction;  
                    command.ExecuteNonQuery();  
 
                    transaction.Commit();  
                }  
                grid.Rebind();  
            }  
            catch (Exception ex)  
            {  
                e.Canceled = true;  
                divError.Visible = true;  
                lblError.Text = ex.Message;  
            }  
        }  
    }  
 
0
Perry
Top achievements
Rank 1
answered on 09 Dec 2009, 10:10 PM
<telerik:RadGrid ID="grid" runat="server" DataSourceID="csdepartment" GridLines="None" AllowFilteringByColumn="True" 
                             AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" ShowGroupPanel="True" PageSize="20" 
                             OnItemCommand="ItemCommand" ShowFooter="true" 
            > 
                <HeaderContextMenu EnableTheming="True">  
                    <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
                </HeaderContextMenu> 
 
                <MasterTableView DataKeyNames="email" DataSourceID="csdepartment" CommandItemDisplay="TopAndBottom" Comm> 
                    <EditFormSettings EditFormType="Template">  
                        <EditColumn UniqueName="EditCommandColumn1"></EditColumn> 
                        <FormTemplate> 
                            <table> 
                            <tr> 
                                <td> 
                                    Last:  
                                </td> 
                                <td> 
                                    <asp:TextBox runat="server" ID="tblastname" Text='<%# Bind("lastname") %>'></asp:TextBox> 
                                </td> 
                            </tr> 
                            <tr> 
                                <td> 
                                    First:  
                                </td> 
                                <td> 
                                    <asp:TextBox runat="server" ID="tbfirstname" Text='<%# Bind("firstname") %>'></asp:TextBox> 
                                </td> 
                            </tr> 
                            <tr> 
                                <td> 
                                    Email:  
                                </td> 
                                <td> 
                                    <asp:TextBox runat="server" ID="tbemail" Text='<%# Bind("email") %>' Enabled='<%# (Container is GridEditFormInsertItem) ? true : false %>'></asp:TextBox> 
                                    <asp:RequiredFieldValidator runat="server" Display="Dynamic" ControlToValidate="tbemail">Required</asp:RequiredFieldValidator> 
                                    <asp:RegularExpressionValidator runat="server" Display="Dynamic" ControlToValidate="tbemail" ValidationExpression="^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$">Must be valid email address</asp:RegularExpressionValidator>                                    
                                </td> 
                                      
                                </td> 
                            </tr> 
                            <tr> 
                                <td> 
                                    Job:  
                                </td> 
                                <td> 
                                    <asp:DropDownList ID="ddljob" runat="server" SelectedValue='<%# (Container is GridEditFormInsertItem) ? "5" : Eval("jobid") %>' DataValueField="jobid" DataTextField="description" DataSourceID="jobs">  
                                    </asp:DropDownList> 
                                </td> 
                                </td> 
                            </tr> 
                            <tr> 
                                <td> 
                                    Amount:  
                                </td> 
                                <td> 
                                    <asp:TextBox runat="server" ID="tbamount" Text='<%# Bind("amount") %>'></asp:TextBox> 
                                </td> 
                            </tr> 
                            </table> 
                            <asp:LinkButton ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>' runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'></asp:LinkButton>&nbsp;  
                            <asp:LinkButton ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False" CommandName="Cancel"></asp:LinkButton> 
                        </FormTemplate> 
                    </EditFormSettings> 
                    <RowIndicatorColumn> 
                        <HeaderStyle Width="20px"></HeaderStyle> 
                    </RowIndicatorColumn> 
                    <ExpandCollapseColumn> 
                        <HeaderStyle Width="20px"></HeaderStyle> 
                    </ExpandCollapseColumn> 
                    <Columns> 
                        <telerik:GridEditCommandColumn></telerik:GridEditCommandColumn> 
                        <telerik:GridBoundColumn DataField="lastname" HeaderText="Last" SortExpression="lastname" UniqueName="lastname" AllowSorting="true" AllowFiltering="true">  
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn DataField="firstname" HeaderText="First" SortExpression="firstname" UniqueName="firstname" AllowSorting="true" AllowFiltering="true">  
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn DataField="email" HeaderText="Email" ReadOnly="True" SortExpression="email" UniqueName="email">  
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn DataField="jobid" DataType="System.Int32" HeaderText="jobid" ReadOnly="True" SortExpression="jobid" UniqueName="jobid" Visible="false">  
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn DataField="description" HeaderText="Job Function" SortExpression="description" UniqueName="description">  
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn DataField="amount" DataType="System.Decimal" HeaderText="Amount" ReadOnly="True" SortExpression="amount" UniqueName="amount" Aggregate="Sum">  
                        </telerik:GridBoundColumn> 
                    </Columns> 
                </MasterTableView> 
                <ClientSettings AllowDragToGroup="True">  
                </ClientSettings> 
 
                <FilterMenu EnableTheming="True">  
                    <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
                </FilterMenu> 
            </telerik:RadGrid> 
0
Perry
Top achievements
Rank 1
answered on 09 Dec 2009, 10:25 PM
I eliminated the declarative datasource syntax and am using the NeedData method.

There are NO automatic updates/inserts/deletes enabled.

Same result.
0
Princy
Top achievements
Rank 2
answered on 10 Dec 2009, 06:13 AM
Hello Perry,

Try the following code and see if it helps to close the insert form:
c#:
protected void RadGrid1_InsertCommand(object source, GridCommandEventArgs e) 
    { 
        // insert query  
 
        RadGrid1.MasterTableView.IsItemInserted = false
        RadGrid1.MasterTableView.Rebind();  
    } 

Thanks
Princy.
Tags
Grid
Asked by
Perry
Top achievements
Rank 1
Answers by
Perry
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or