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

Use Of both EditFormType="Template" AND EditFormType="EditForm"

3 Answers 110 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Swapnil
Top achievements
Rank 1
Swapnil asked on 26 Nov 2013, 10:26 AM
Hi,
i want to Use Of both EditFormType="Template"(for Insert Because of all field)  AND EditFormType="EditForm"(because of some field which are shown in grid)
My code is:
<%@ Page Title="" Language="C#" MasterPageFile="~/MPLayout.master" AutoEventWireup="true"
    CodeFile="UserDetailsGrid.aspx.cs" Inherits="EntityDetailsGrid" %>
 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    
    <telerik:RadAjaxManager ID="RadAjaxManager1" DefaultLoadingPanelID="RadAjaxLoadingPanel1"
        ClientEvents-OnRequestStart="onRequestStart" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadGrid1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1"></telerik:AjaxUpdatedControl>
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <telerik:RadWindowManager ID="RadWindowManager1" runat="server" Animation="Slide"
        KeepInScreenBounds="true" Skin="Outlook" MaxHeight="130px" MaxWidth="360px">
    </telerik:RadWindowManager>
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Transparency="5"
        Skin="Outlook" />
    <script type="text/javascript">
        function onRequestStart(sender, args) {
            if (args.get_eventTarget().indexOf("ExportTo") >= 0) {
                args.set_enableAjax(false);
            }
        }
    </script>
    <telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="true" AllowSorting="true"
        Skin="Outlook" HeaderStyle-Font-Bold="true" HeaderStyle-Font-Size="13px" HeaderStyle-Font-Names="Verdana"
        ItemStyle-Font-Names="Verdana" AlternatingItemStyle-Font-Names="Verdana" ShowGroupPanel="true"
        OnPreRender="RadGrid1_PreRender"
        OnNeedDataSource="RadGrid1_NeedDataSource1"
        onitemcommand="RadGrid1_ItemCommand1" onitemdeleted="RadGrid1_ItemDeleted"
        oniteminserted="RadGrid1_ItemInserted" onitemupdated="RadGrid1_ItemUpdated">
        <PagerStyle AlwaysVisible="true" Font-Bold="true" Mode="NextPrevNumericAndAdvanced" />
        <ClientSettings AllowDragToGroup="true" AllowColumnsReorder="true" Resizing-AllowResizeToFit="true">
            <Selecting AllowRowSelect="True" UseClientSelectColumnOnly="True"></Selecting>
        </ClientSettings>
        <ExportSettings ExportOnlyData="true" OpenInNewWindow="true" IgnorePaging="true"
            FileName="Entity Details">
            <Pdf AllowAdd="true" AllowCopy="true" AllowModify="true" AllowPrinting="true" BorderColor="Black"
                BorderStyle="Medium" BorderType="AllBorders" PageBottomMargin="20px" PageFooter-LeftCell-TextAlign="Center"
                PageFooterMargin="20px" PageHeader-LeftCell-TextAlign="Center" PageHeaderMargin="20px"
                PageLeftMargin="35px" PageRightMargin="35px" PageTitle="List Of Entities and Details"
                PageTopMargin="35px" PaperSize="A4" UserPassword="ss">
            </Pdf>
        </ExportSettings>
        <MasterTableView CommandItemDisplay="Top" CommandItemSettings-ShowAddNewRecordButton="true"
            EditMode="EditForms" DataKeyNames="UserId" CommandItemSettings-ShowRefreshButton="false">
            <CommandItemSettings ShowExportToCsvButton="true" ShowExportToExcelButton="true"
                ShowExportToPdfButton="true" ShowExportToWordButton="true" />
            <EditFormSettings FormMainTableStyle-HorizontalAlign="Center" EditColumn-ButtonType="PushButton"
                FormTableStyle-Width="100%" FormTableButtonRowStyle-HorizontalAlign="Center"
                FormTableStyle-CellPadding="3" FormMainTableStyle-Font-Bold="true" FormMainTableStyle-ForeColor="Purple"
                FormStyle-CssClass="" FormTableStyle-CellSpacing="5" InsertCaption="Add New User Details"
                FormCaptionStyle-Font-Bold="true" FormCaptionStyle-Font-Underline="true" FormCaptionStyle-ForeColor="Black"
                FormCaptionStyle-Font-Size="Large" FormCaptionStyle-HorizontalAlign="Center"
                FormCaptionStyle-Width="100%">
                <FormStyle Width="100%" BackColor="LightCyan"></FormStyle>
            </EditFormSettings>
            <EditFormSettings EditFormType="Template">
                <FormTemplate>
                    <center>
                        <u>
                            <h4>
                                Add New User Details</h4>
                        </u>
                        <table style="font-family: Verdana; padding: 10px" cellspacing="5" cellpadding="3">
                            <tr>
                                <td>
                                    User Name
                                </td>
                                <td>
                                    <asp:TextBox ID="tempUserName" runat="server" Width="200px" Font-Names="Verdana">
                                    </asp:TextBox>
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="tempUserName"
                                        Font-Bold="true" ErrorMessage="*" ValidationGroup="Save"></asp:RequiredFieldValidator>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    First Name
                                </td>
                                <td>
                                    <asp:TextBox ID="tempFirstName" runat="server" Width="200px" Font-Names="Verdana">
                                    </asp:TextBox>
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="tempFirstName"
                                        Font-Bold="true" ErrorMessage="*" ValidationGroup="Save"></asp:RequiredFieldValidator>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Last Name
                                </td>
                                <td>
                                    <asp:TextBox ID="tempLastName" runat="server" Width="200px" Font-Names="Verdana">
                                    </asp:TextBox>
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="tempLastName"
                                        Font-Bold="true" ErrorMessage="*" ValidationGroup="Save"></asp:RequiredFieldValidator>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    User Email
                                </td>
                                <td>
                                    <asp:TextBox ID="tempUserEmail" runat="server" Width="200px" Font-Names="Verdana">
                                    </asp:TextBox>
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="tempUserEmail"
                                        ErrorMessage="*" ValidationGroup="Save"></asp:RequiredFieldValidator>
                                    <asp:RegularExpressionValidator ID="Rev1" runat="server" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
                                        ErrorMessage="* Invalid Email" ValidationGroup="Save" ForeColor="Red" ControlToValidate="tempUserEmail"></asp:RegularExpressionValidator>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Phone No
                                </td>
                                <td>
                                    <asp:TextBox ID="tempPhoneNo" runat="server" Width="200px">
                                    </asp:TextBox>
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="tempPhoneNo"
                                        ErrorMessage="*" ValidationGroup="Save"></asp:RequiredFieldValidator>
                                    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ValidationExpression="^\d+$"
                                        ErrorMessage="* Invalid PhoneNo" ValidationGroup="Save" ForeColor="Red" ControlToValidate="tempPhoneNo"></asp:RegularExpressionValidator>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    User Type
                                </td>
                                <td>
                                    <telerik:RadComboBox ID="cmbusertype" runat="server" Width="207px" Height="200px"
                                        Font-Names="Verdana" Skin="Hay" EnableLoadOnDemand="true" MarkFirstMatch="true"
                                        EmptyMessage="Please Select User Type" />
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ControlToValidate="cmbusertype"
                                        Font-Bold="true" ErrorMessage="*" ValidationGroup="Save"></asp:RequiredFieldValidator>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Comapny Name
                                </td>
                                <td>
                                    <telerik:RadComboBox ID="cmbcompanyname" runat="server" Width="207px" Height="200px"
                                        Font-Names="Verdana" Skin="Hay" EnableLoadOnDemand="true" MarkFirstMatch="true"
                                        EmptyMessage="Please Select Company Name" />
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ControlToValidate="cmbcompanyname"
                                        Font-Bold="true" ErrorMessage="*" ValidationGroup="Save"></asp:RequiredFieldValidator>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Password
                                </td>
                                <td>
                                    <asp:TextBox ID="tempPassword" runat="server" Width="200px" TextMode="Password">
                                    </asp:TextBox>
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server" ControlToValidate="tempPassword"
                                        Font-Bold="true" ErrorMessage="*" ValidationGroup="Save"></asp:RequiredFieldValidator>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Confirm Password
                                </td>
                                <td>
                                    <asp:TextBox ID="tempConfirmPassword" runat="server" Width="200px" TextMode="Password">
                                    </asp:TextBox>
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server" ControlToValidate="tempConfirmPassword"
                                        Font-Bold="true" ErrorMessage="*" ValidationGroup="Save"></asp:RequiredFieldValidator>
                                </td>
                            </tr>
                            <tr>
                                <td align="right" colspan="2">
                                    <asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
                                        runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'>
                                    </asp:Button
                                    <asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False"
                                        CommandName="Cancel"></asp:Button>
                                </td>
                            </tr>
                        </table>
                      
                    </center>
                    <br />
                </FormTemplate>
            </EditFormSettings>
            <Columns>
                <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditColumn">
                </telerik:GridEditCommandColumn>
                <telerik:GridButtonColumn CommandName="Delete" ButtonType="ImageButton" UniqueName="DeleteColumn"
                    ConfirmText="Are you sure to Delete this Entity?" ConfirmDialogType="RadWindow"
                    ConfirmTitle="<b>Manifest-BI</b>">
                </telerik:GridButtonColumn>
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>
</asp:Content>
AND
using System;
using System.Web;
using System.Linq;
using System.Data;
using System.Web.UI;
using Telerik.Web.UI;
using System.Collections;
using System.Web.UI.WebControls;
using System.Collections.Generic;
 
 
public partial class EntityDetailsGrid : System.Web.UI.Page
{
    Globas ObjGlobas = new Globas();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Convert.ToInt32(Session["RoleId"].ToString()) == 3)
        {
            Response.Redirect("ErrorPage.aspx");
        }
        BindGrid();
    }
 
 
    #region[-------Find Entity Id Column To Hide Before Page Load-------]
    protected void RadGrid1_PreRender(object sender, EventArgs e)
    {
        RadGrid1.MasterTableView.GetColumn("UserId").Visible = false;
    }
    #endregion
 
 
 
 
    #region[--------RadGrid Advanced Data Binding-------]
    protected void RadGrid1_NeedDataSource1(object sender, GridNeedDataSourceEventArgs e)
    {
        DataTable DtUserDetails = ObjGlobas.UserDetails();
        DtUserDetails.Columns.Remove("CompId");
        DtUserDetails.Columns.Remove("Password");
        DtUserDetails.Columns.Remove("UserAccessCode");
        DtUserDetails.Columns.Remove("Status");
        DtUserDetails.Columns.Remove("StartDate");
        DtUserDetails.Columns.Remove("EndDate");
        DtUserDetails.Columns.Remove("UserTypeId");
        RadGrid1.DataSource = DtUserDetails;
    }
    #endregion
 
    #region[-------PAGELOAD GRID BIND-------]
    public void BindGrid()
    {
 
        DataTable DtUserDetails = ObjGlobas.UserDetails();
        DtUserDetails.Columns.Remove("CompId");
        DtUserDetails.Columns.Remove("Password");
        DtUserDetails.Columns.Remove("UserAccessCode");
        DtUserDetails.Columns.Remove("Status");
        DtUserDetails.Columns.Remove("StartDate");
        DtUserDetails.Columns.Remove("EndDate");
        DtUserDetails.Columns.Remove("UserTypeId");
        RadGrid1.DataSource = DtUserDetails;
    }
    #endregion
 
 
 
   
    protected void RadGrid1_ItemCommand1(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == RadGrid.EditCommandName)
        {
            RadGrid1.MasterTableView.IsItemInserted = false;    //Close Insert Form When EditMode Is Open
        }
        if (e.CommandName == RadGrid.InitInsertCommandName)
        {
            RadGrid1.MasterTableView.ClearEditItems();         //Close EditMode Form When Insert Mode Is Open
        }
 
        //To Find Delete & Edit Columns And Hide Their Text While Exporting Grid To PDF & Excel & Word
        if (e.CommandName == RadGrid.ExportToPdfCommandName || e.CommandName == RadGrid.ExportToExcelCommandName || e.CommandName == RadGrid.ExportToCsvCommandName || e.CommandName == RadGrid.ExportToWordCommandName)
        {
            RadGrid1.MasterTableView.GetColumn("EditColumn").Visible = false;
            RadGrid1.MasterTableView.GetColumn("DeleteColumn").Visible = false;
        }
    }
}

Please Want some help,
Thanks

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 26 Nov 2013, 10:55 AM
Hi Swapnil,

Please add the following code snippet to the ItemCommand event of the RadGrid to open Template form during insert and EditForm during edit.

C#:
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.InitInsertCommandName)
    {
        e.Canceled = true;
        RadGrid1.EditIndexes.Clear();
        e.Item.OwnerTableView.EditFormSettings.EditFormType = GridEditFormType.Template;
        e.Item.OwnerTableView.InsertItem();
    }
    else if (e.CommandName == RadGrid.EditCommandName)
    {
        e.Item.OwnerTableView.IsItemInserted = false;
        e.Item.OwnerTableView.EditFormSettings.EditFormType = GridEditFormType.AutoGenerated;
    }
}

Thanks,
Princy
0
Swapnil
Top achievements
Rank 1
answered on 26 Nov 2013, 11:25 AM
Thanks Princy for too quick answer,
can u just tell me how can i get the textbox values on codebehind and what will be the event for insert command ?
Thanks
0
Shinu
Top achievements
Rank 2
answered on 27 Nov 2013, 03:59 AM
Hi Swapnil,

The InsertCommand event of the RadGrid is used for performing insert operation on the RadGrid. I guess you want to access the TextBox in this event. Please try the following code snippet and let me know if any concerns.

C#:
protected void RadGrid1_InsertCommand(object sender, GridCommandEventArgs e)
{
  if (e.Item is GridEditableItem)
  {
      GridEditableItem edit = (GridEditableItem)e.Item;
      TextBox txt = (TextBox)edit.FindControl("TextBoxID"); // Access the textbox here using its ID
  }
}

Thanks,
Shinu

Tags
Grid
Asked by
Swapnil
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Swapnil
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or