RadGrid FormTemplate Controls

2 posts, 0 answers
  1. Salman
    Salman avatar
    3 posts
    Member since:
    Nov 2018

    Posted 21 Mar Link to this post

    Hello,

    I have the following FormTemplate that I am using to update/insert. However, I am having issues attempting to read the values of the control. Can someone please advise on how to read controls best, so that I can add these values to the SQL database? I cannot automatically add the values due to having some conditions before adding. Thank you!

     

       <EditFormSettings EditFormType="Template">     
                    <FormTemplate>                   
                        <asp:Label runat="server" Text="Closure Location: " Font-Bold="true">
                            <telerik:RadComboBox ID="ddSiteList" runat="server" CheckBoxes="true" EnableCheckAllItemsCheckBox="true">                     
                                </telerik:RadComboBox>                    
                        </asp:Label>
                        <asp:Label runat="server" Font-Bold="true" Text="Order Type">
                            <telerik:RadDropDownList ID="ddType" runat="server" DefaultMessage="Select Order Types">             
                                <Items>                            
                                <telerik:DropDownListItem Text="All Types" Value="0"></telerik:DropDownListItem>
                                <telerik:DropDownListItem Text="Online Only" Value="1"></telerik:DropDownListItem>
                                </Items>
                            </telerik:RadDropDownList>
                        </asp:Label>
                        <asp:Label ID="lblReason" runat="server" Text="Closure Reason: " Font-Bold="true"> 
                            <asp:DropDownList ID="ddReasons" runat="server">
                                <asp:ListItem Text="Please select a reason" Value=""></asp:ListItem>
                            </asp:DropDownList>
                        </asp:Label>   
                        <asp:Label ID="lblFullDay" runat="server" Text="Duration: " Font-Bold="true">
                            <telerik:RadDropDownList ID="ddDuration" runat="server">
                                <Items>
                                <telerik:DropDownListItem Text="Please Select" Value=""></telerik:DropDownListItem>
                                <telerik:DropDownListItem Text="Partial" Value="0"></telerik:DropDownListItem>
                                <telerik:DropDownListItem Text="Full Day" Value="1"></telerik:DropDownListItem>
                                </Items>
                            </telerik:RadDropDownList>
                        </asp:Label>
                        <asp:Label runat="server" Text="Start Time: ">
                            <telerik:RadDateTimePicker RenderMode="Lightweight"  runat="server" ID="timeStart" ></telerik:RadDateTimePicker>
                        </asp:Label>
                        <asp:Label runat="server" Text="End Time: ">
                            <telerik:RadDateTimePicker RenderMode="Lightweight"   runat="server" ID="timeEnd"></telerik:RadDateTimePicker>
                        </asp:Label>
                        <asp:Label ID="lblDescription" runat="server" Text="Closure Reason: ">
                            <telerik:RadTextBox ID="txtDescription" runat="server"></telerik:RadTextBox>
                        </asp:Label>
                        <asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
                            runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'></asp:Button>&nbsp;
                        <asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False" CommandName="Cancel"></asp:Button>                    
                    </FormTemplate>
                </EditFormSettings>

     

    C# 

      protected void rgClosureList_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
            {
                if (e.CommandName == "PerformInsert")
                {
                    if ((e.Item is GridEditableItem) && (e.Item.IsInEditMode))
                    {                 
                        RadTextBox ddValue = FindControl("txtDescription") as RadTextBox;
                        string sValue = ddValue.Text;

                      //Open Sql connection and insert values into DB

                    }

                    if (e.CommandName == "Update")
                    {
                      //Open Sql connection and insert values into DB
                    }

                }

     

  2. Vessy
    Admin
    Vessy avatar
    2039 posts

    Posted 26 Mar Link to this post

    Hi Salman,

    The ItemCommand event of the Grid for the EditCommand is triggered just after the Edit button is clicked and the controls inside the template are still not available at this moment. In order to apply any changes to the controls inside the Grid edit form template, you have to do it in the ItemDataBound event, by checking if the current item is in EditMode. You can find more details on the matter here:
    https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/rows/accessing-cells-and-rows#accessing-controls-in-editinsert-mode

    For example:
    protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
    {
        if (e.Item is GridEditableItem && e.Item.IsInEditMode && !(e.Item is GridEditFormInsertItem))
        {
            GridEditableItem editFormInsertItem = e.Item as GridEditableItem;
            RadTextBox ddValue = (RadTextBox)editFormInsertItem.FindControl("txtDescription");
            string sValue = ddValue.Text;
        }
        else if (e.Item is GridEditFormInsertItem && e.Item.IsInEditMode)
        {
            GridEditFormInsertItem insertFormInsertItem = e.Item as GridEditFormInsertItem;
            RadTextBox ddValue = (RadTextBox)insertFormInsertItem.FindControl("txtDescription");
            string sValue = ddValue.Text;
        }
    }


    Regards,
    Vessy
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top