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

RadTreeList Editmode to be closed

4 Answers 110 Views
UI for ASP.NET AJAX in ASP.NET MVC
This is a migrated thread and some comments may be shown as answers.
Tamim
Top achievements
Rank 1
Tamim asked on 28 Feb 2013, 11:31 AM

I have used RadTreeList see my image.
1. Add new node to popup window then insert. Here one problem Code will be mandatory field set.
Code not enter to save alert message display but Popup window(new record insert) to be closed

My aspx code below:

<telerik:RadTreeList ID="RadTreeListWork" runat="server" OnNeedDataSource="RadTreeListWork_NeedDataSource"
                        OnUpdateCommand="RadTreeListWork_UpdateCommand" OnInsertCommand="RadTreeListWork_InsertCommand"
                        ParentDataKeyNames="WorkParentId" DataKeyNames="WorkId" AutoGenerateColumns="False"
                        OnItemDataBound="RadTreeListWork_ItemDataBound" EditMode="PopUp" OnDeleteCommand="RadTreeListWork_DeleteCommand"
                        OnItemCreated="RadTreeListWork_ItemCreated" AllowMultiItemEdit="False" Culture="(Default)"
                        GridLines="None" IsItemInserted="False" ShowOuterBorders="False" Width="500px"
                        PageSize="10" AllowPaging="true">
                        <Columns>
                            <telerik:TreeListEditCommandColumn UniqueName="InsertCommandColumn" ButtonType="ImageButton"
                                ShowEditButton="false" HeaderStyle-Width="20px" ItemStyle-HorizontalAlign="Center" />
                            <telerik:TreeListButtonColumn CommandName="Edit" Text="Edit" UniqueName="EditCommandColumn"
                                ButtonType="ImageButton" HeaderStyle-Width="20px" ItemStyle-HorizontalAlign="Center" />
                            <telerik:TreeListBoundColumn DataField="WorkId" HeaderText="WorkId" ReadOnly="true"
                                UniqueName="WorkId" HeaderStyle-Width="75px" ForceExtractValue="Always" Visible="false" />
                            <telerik:TreeListBoundColumn DataField="WorkParentId" HeaderText="WorkParentId" HeaderStyle-Width="65px"
                                UniqueName="WorkParentId" ReadOnly="true" ForceExtractValue="Always" Visible="false" />
                            <telerik:TreeListBoundColumn DataField="WorkName" HeaderText="Name" UniqueName="WorkName"
                                HeaderStyle-Width="100px" />
                            <telerik:TreeListBoundColumn DataField="WorkDescription" HeaderText="Description"
                                UniqueName="WorkDescription" HeaderStyle-Width="200px" />
                            <telerik:TreeListBoundColumn DataField="UnitCode" HeaderText="Unit" UniqueName="UnitCode"
                                HeaderStyle-Width="100px" />
                            <telerik:TreeListTemplateColumn DataField="Quantity" HeaderText="Quantity" UniqueName="Quantity"
                                HeaderStyle-Width="100px">
                                <ItemTemplate>
                                    <asp:Label runat="server" ID="Qty" Text='<%# Eval("Quantity") %>'></asp:Label>
                                </ItemTemplate>
                            </telerik:TreeListTemplateColumn>
                            <telerik:TreeListTemplateColumn DataField="Rate" HeaderText="Rate" UniqueName="Rate"
                                HeaderStyle-Width="100px">
                                <ItemTemplate>
                                    <asp:Label runat="server" ID="Rte" Text='<%# Eval("Rate") %>'></asp:Label>
                                </ItemTemplate>
                            </telerik:TreeListTemplateColumn>
                            <telerik:TreeListTemplateColumn DataField="Amount" HeaderText="Amount" UniqueName="Amount"
                                HeaderStyle-Width="100px">
                                <ItemTemplate>
                                    <asp:Label runat="server" ID="Amt" Text='<%# Eval("Amount") %>'></asp:Label>
                                </ItemTemplate>
                            </telerik:TreeListTemplateColumn>
                            <telerik:TreeListButtonColumn ButtonType="ImageButton" UniqueName="DeleteCommandColumn"
                                Text="Delete" CommandArgument="Child" CommandName="Delete" HeaderStyle-Width="20px" />
                        </Columns>
                        <ValidationSettings CommandsToValidate="PerformInsert, Update" EnableValidation="true" />
                        <EditFormSettings CaptionFormatString="Create" EditFormType="Template" PopUpSettings-Width="400px">
                            <FormTemplate>
                                <div style="margin-left: 1%;">
                                    <table width="100%">
                                        <tr>
                                            <td style="height: 75px; width: 75%;">
                                                <table style="float: right;">
                                                    <tr>
                                                        <td>
                                                            <asp:Label ID="Label3" runat="server" ForeColor="Red" Text="*" Width="1px"></asp:Label>
                                                            <asp:Label ID="Label2" Text="Mandatory Field(s)" runat="server"></asp:Label>
                                                        </td>
                                                    </tr>
                                                </table>
                                                <br />
                                                <br />
                                                <fieldset>
                                                    <legend style="margin-bottom: 10px">Work Definition</legend>
                                                    <table cellspacing="2" cellpadding="1" width="100%" border="0">
                                                        <tr>
                                                            <td align="right">
                                                                <asp:Label ID="Label1" runat="server" ForeColor="Red" Text="*" Width="1px"></asp:Label>
                                                                Code :
                                                            </td>
                                                            <td>
                                                                <asp:TextBox Width="90%" ID="WorkName" AutoCompleteType="Disabled" runat="server"
                                                                    MaxLength="5" Text='<%# Bind("WorkName") %>'></asp:TextBox>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td valign="top" align="right">
                                                            <asp:Label ID="Label4" runat="server" ForeColor="Red" Text="*" Width="1px"></asp:Label>
                                                                Description :
                                                            </td>
                                                            <td>
                                                                <asp:TextBox Width="90%" ID="WorkDescription" AutoCompleteType="Disabled" runat="server"
                                                                    MaxLength="300" TextMode="MultiLine" Height="100px" Text='<%# Bind("WorkDescription") %>'></asp:TextBox>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td valign="top" align="right">
                                                                Unit :
                                                            </td>
                                                            <td>
                                                                <telerik:RadComboBox runat="server" ID="UnitCode" Skin="Vista" AppendDataBoundItems="True"
                                                                    AutoPostBack="True" DataTextField="UnitName" DataValueField="UnitCode" Height="200px"
                                                                    OnSelectedIndexChanged="UnitCode_SelectedIndexChanged">
                                                                </telerik:RadComboBox>
                                                            </td>
                                                            <%--<td>
                                                                <telerik:RadComboBox runat="server" ID="UnitCode">
                                                                </telerik:RadComboBox>
                                                            </td>--%>
                                                        </tr>
                                                        <tr>
                                                            <td valign="top" align="right">
                                                                <asp:Label ID="Label9" runat="server" ForeColor="Red" Text="*" Width="1px" Visible="false"></asp:Label>
                                                                Quantity :
                                                            </td>
                                                            <td>
                                                                <telerik:RadNumericTextBox Width="50%" ID="Quantity" AutoCompleteType="Disabled"
                                                                    MaxLength="6" FocusedStyle-BackColor="Lavender" runat="server" Text='<%# Bind("Quantity") %>'
                                                                    onkeydown="return (event.keyCode!=13);" ReadOnly="true">
                                                                    <NumberFormat GroupSeparator="" DecimalDigits="0" AllowRounding="true" KeepNotRoundedValue="false" />
                                                                    <IncrementSettings InterceptMouseWheel="false" InterceptArrowKeys="false" />
                                                                    <ClientEvents OnKeyPress="KeyPress" />
                                                                </telerik:RadNumericTextBox>
                                                                <%--<telerik:RadListBox runat="server" ID="UnitNo">
                                                                </telerik:RadListBox>--%>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td valign="top" align="right">
                                                            <asp:Label ID="Label10" runat="server" ForeColor="Red" Text="*" Width="1px" Visible="false"></asp:Label>
                                                                Rate (S$):
                                                            </td>
                                                            <td>
                                                                <telerik:RadNumericTextBox Width="50%" ID="Rate" AutoCompleteType="Disabled" MaxLength="6"
                                                                    ReadOnly="true" FocusedStyle-BackColor="Lavender" runat="server" Text='<%# Bind("Rate") %>'
                                                                    onkeydown="return (event.keyCode!=13);">
                                                                    <NumberFormat GroupSeparator="" DecimalDigits="0" AllowRounding="true" KeepNotRoundedValue="false" />
                                                                    <IncrementSettings InterceptMouseWheel="false" InterceptArrowKeys="false" />
                                                                    <ClientEvents OnKeyPress="KeyPress" />
                                                                </telerik:RadNumericTextBox>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td valign="top" align="right">
                                                                Amount (S$):
                                                            </td>
                                                            <td>
                                                                <telerik:RadNumericTextBox Width="50%" ID="Amount" AutoCompleteType="Disabled" MaxLength="6"
                                                                    FocusedStyle-BackColor="Lavender" runat="server" Text='<%# Bind("Amount") %>'
                                                                    onkeydown="return (event.keyCode!=13);" ReadOnly="true">
                                                                    <NumberFormat GroupSeparator="" DecimalDigits="0" AllowRounding="true" KeepNotRoundedValue="false" />
                                                                    <IncrementSettings InterceptMouseWheel="false" InterceptArrowKeys="false" />
                                                                    <ClientEvents OnKeyPress="KeyPress" />
                                                                </telerik:RadNumericTextBox>
                                                            </td>
                                                        </tr>
                                                    </table>
                                                </fieldset>
                                            </td>
                                        </tr>
                                    </table>
                                    <table>
                                        <tr>
                                            <td>
                                                <telerik:RadButton ID="btnUpdate" Text='<%# (Container is TreeListEditFormInsertItem) ? "Insert" : "Update" %>'
                                                    runat="server" CommandName='<%# (Container is TreeListEditFormInsertItem) ? "PerformInsert" : "Update" %>'
                                                    Icon-PrimaryIconCssClass="rbOk">
                                                </telerik:RadButton>
                                                &nbsp;
                                                <telerik:RadButton ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False"
                                                    CommandName="Cancel" Icon-PrimaryIconCssClass="rbCancel">
                                                </telerik:RadButton>
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                            </FormTemplate>
                            <PopUpSettings Modal="True"></PopUpSettings>
                        </EditFormSettings>
                    </telerik:RadTreeList>

Advance & Thanks,
Ansari

4 Answers, 1 is accepted

Sort by
0
Marin
Telerik team
answered on 05 Mar 2013, 09:06 AM
Hello,

One way to manually close the inser form is to clear the insert indexes of the treelist and then rebind the control:

RadTreeList1.InsertIndexes.Clear();
RadTreeList1.Rebind();

Regards,
Marin
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Tamim
Top achievements
Rank 1
answered on 05 Mar 2013, 10:37 AM
Thanks for ur reply Marin.

Treelist rebind close to edit mode popup window are closed.

This is my sample aspx.cs coding

protected void RadTreeListWork_InsertCommand(object sender, TreeListCommandEventArgs e)
        {
            if (e.CommandName == RadTreeList.PerformInsertCommandName)
            {
                string commandText = "INSERT INTO [WorkDefination] ([WorkParentId],[WorkName], [WorkDescription],[Quantity],[Rate],[Amount],[UnitCode],[ProjCode],[CompCode] ) VALUES " +
                                    "(@WorkParentId,@WorkName, @WorkDescription,@Quantity,@Rate,@Amount,@UnitCode,@ProjCode,@CompCode)";

                SqlConnection conn = new SqlConnection(oDBClientADO.ConnectionString);
                SqlCommand command = new SqlCommand(commandText, conn);
                Hashtable table = new Hashtable();

                TreeListEditFormInsertItem item = e.Item as TreeListEditFormInsertItem;

                table["WorkName"] = (item.FindControl("WorkName") as TextBox).Text;
                table["WorkDescription"] = (item.FindControl("WorkDescription") as TextBox).Text;
                table["Quantity"] = (item.FindControl("Quantity") as RadNumericTextBox).Text;
                table["Rate"] = (item.FindControl("Rate") as RadNumericTextBox).Text;
                table["Amount"] = (item.FindControl("Amount") as RadNumericTextBox).Text;
                table["UnitCode"] = (item.FindControl("UnitCode") as RadComboBox).SelectedValue;
                table["ProjCode"] = projcode;
                table["CompCode"] = compcode;
                if (table["UnitCode"].ToString() == "-1" || table["UnitCode"].ToString() == "LUM")
                {
                    if (table["WorkName"] != "" && table["WorkDescription"] != "")
                    {
                        if (ansa == 0)
                        {
                            command.Parameters.AddWithValue("WorkName", table["WorkName"]);
                            command.Parameters.AddWithValue("WorkDescription", table["WorkDescription"]);
                            if (table["UnitCode"].ToString() == "LUM")
                                command.Parameters.AddWithValue("Quantity", 100);
                            else
                                command.Parameters.AddWithValue("Quantity", table["Quantity"]);

                            command.Parameters.AddWithValue("Rate", table["Rate"]);
                            command.Parameters.AddWithValue("Amount", table["Amount"]);

                            if ((item.FindControl("UnitCode") as RadComboBox).SelectedValue == "-1")
                            {
                                command.Parameters.AddWithValue("UnitCode", "");
                            }
                            else
                                command.Parameters.AddWithValue("UnitCode", table["UnitCode"]);
                            command.Parameters.AddWithValue("ProjCode", table["ProjCode"]);
                            command.Parameters.AddWithValue("CompCode", table["CompCode"]);
                            if (table["UnitCode"].ToString() == "LUM" && table["Amount"] == "")
                            {
                                RadAjaxManager1.Alert("Please Enter Amount");
                                (item.FindControl("WorkName") as TextBox).Focus();
                            }
                            else
                            {
                                object parentValue;
                                if (item.ParentItem != null)
                                {
                                    parentValue = item.ParentItem.GetDataKeyValue("WorkId");
                                }
                                else
                                {
                                    parentValue = DBNull.Value;
                                }

                                command.Parameters.AddWithValue("WorkParentId", parentValue);
                                conn.Open();
                                try
                                {
                                    command.ExecuteNonQuery();

                                }
                                finally
                                {
                                    conn.Close();
                                }
                            }

                        }
                        else
                        {
                            if (table["Amount"] != "")
                            {
                                command.Parameters.AddWithValue("WorkName", table["WorkName"]);
                                command.Parameters.AddWithValue("WorkDescription", table["WorkDescription"]);
                                if (table["UnitCode"].ToString() == "LUM")
                                    command.Parameters.AddWithValue("Quantity", 100);
                                else
                                    command.Parameters.AddWithValue("Quantity", table["Quantity"]);
                                command.Parameters.AddWithValue("Rate", table["Rate"]);
                                command.Parameters.AddWithValue("Amount", table["Amount"]);

                                if ((item.FindControl("UnitCode") as RadComboBox).SelectedValue == "-1")
                                {
                                    command.Parameters.AddWithValue("UnitCode", "");
                                }
                                else
                                    command.Parameters.AddWithValue("UnitCode", table["UnitCode"]);
                                command.Parameters.AddWithValue("ProjCode", table["ProjCode"]);
                                command.Parameters.AddWithValue("CompCode", table["CompCode"]);
                                if (table["UnitCode"].ToString() == "LUM" && table["Amount"] == "")
                                {
                                    RadAjaxManager1.Alert("Please Enter Amount");
                                    (item.FindControl("WorkName") as TextBox).Focus();
                                }
                                else
                                {
                                    object parentValue;
                                    if (item.ParentItem != null)
                                    {
                                        parentValue = item.ParentItem.GetDataKeyValue("WorkId");
                                    }
                                    else
                                    {
                                        parentValue = DBNull.Value;
                                    }

                                    command.Parameters.AddWithValue("WorkParentId", parentValue);
                                    conn.Open();
                                    try
                                    {
                                        command.ExecuteNonQuery();

                                    }
                                    finally
                                    {
                                        conn.Close();
                                    }
                                }
                            }
                            else
                            {
                                RadAjaxManager1.Alert("Please Enter Amount");
                                (item.FindControl("Amount") as RadNumericTextBox).Focus();
                            }
                        }
                    }
                    else
                    {
                        if (table["WorkName"] == "")
                        {
                            RadAjaxManager1.Alert("Please Enter Code");
                            (item.FindControl("WorkName") as TextBox).Focus();
                        }
                        else if (table["WorkDescription"] == "")
                        {
                            RadAjaxManager1.Alert("Please Enter Description");
                            (item.FindControl("WorkDescription") as TextBox).Focus();
                        }
                    }
                }
                else
                {
                    if (table["WorkName"] != "" && table["WorkDescription"] != "" && table["Quantity"] != "" && table["Rate"] != "")
                    {
                        command.Parameters.AddWithValue("WorkName", table["WorkName"]);
                        command.Parameters.AddWithValue("WorkDescription", table["WorkDescription"]);
                        command.Parameters.AddWithValue("Quantity", table["Quantity"]);
                        command.Parameters.AddWithValue("Rate", table["Rate"]);
                        command.Parameters.AddWithValue("Amount", table["Amount"]);

                        command.Parameters.AddWithValue("UnitCode", table["UnitCode"]);
                        command.Parameters.AddWithValue("ProjCode", table["ProjCode"]);
                        command.Parameters.AddWithValue("CompCode", table["CompCode"]);

                        object parentValue;
                        if (item.ParentItem != null)
                        {
                            parentValue = item.ParentItem.GetDataKeyValue("WorkId");
                        }
                        else
                        {
                            parentValue = DBNull.Value;
                        }

                        command.Parameters.AddWithValue("WorkParentId", parentValue);
                        conn.Open();
                        try
                        {
                            command.ExecuteNonQuery();

                        }
                        finally
                        {
                            conn.Close();
                        }
                    }
                    else
                    {
                        if (table["WorkName"] == "")
                        {
                            RadAjaxManager1.Alert("Please Enter Code");
                            (item.FindControl("WorkName") as TextBox).Focus();
                        }
                        else if (table["WorkDescription"] == "")
                        {
                            RadAjaxManager1.Alert("Please Enter Description");
                            (item.FindControl("WorkDescription") as TextBox).Focus();
                        }
                        else if (table["Quantity"] == "")
                        {
                            RadAjaxManager1.Alert("Please Enter Quantity");
                            (item.FindControl("Quantity") as RadNumericTextBox).Focus();
                        }
                        else if (table["Rate"] == "")
                        {
                            RadAjaxManager1.Alert("Please Enter Rate");
                            (item.FindControl("Quantity") as RadNumericTextBox).Focus();
                        }
                    }
                }
            }

        }

Thanks,
Ansari.
0
Marin
Telerik team
answered on 06 Mar 2013, 04:50 PM
Hi,

 The validation for the TreeList looks properly configured. The cancel button should close the popup window and the insert button should fire the validation and prevent page page from posting back to the server. The behavior can also be checked in the following online demo.

Kind regards,
Marin
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Tamim
Top achievements
Rank 1
answered on 22 Mar 2013, 01:51 PM
Thanks for ur reply Marin

Thanks,
Ansari
Tags
UI for ASP.NET AJAX in ASP.NET MVC
Asked by
Tamim
Top achievements
Rank 1
Answers by
Marin
Telerik team
Tamim
Top achievements
Rank 1
Share this question
or