New to Telerik UI for ASP.NET AJAXStart a free 30-day trial

Different Edit and Insert Forms

In number of cases it can be more convenient to have different edit/insert form when configuring EditForms edit mode for your grid instance. This can be especially helpful when you want to allow the user enter value for some of the grid columns on insert (for the newly created record in the grid) but forbid that on edit command. The sample approach below represents how to implement this functionality with minimum amount of code (residing in the ItemCommand handler of the grid). These are the main points:

  • when the command name passed through the e.CommandName argument is either Edit, PerformInsert or Cancel, hide the corresponding column in the grid and set it as read-only.

  • when the command name is InitInsert, cancel the default insert action and display the column editor for the hidden column by setting its ReadOnly property to false. The additional Display="true" setting is used when the EditForm attribute of the grid table is set to InPlace.

Note that you can extend the example to switch the visibility for multiple column editor instances on insert/update.

ASP.NET
<telerik:RadGrid RenderMode="Lightweight" ID="RadGrid1" runat="server" Width="400px">
  <MasterTableView CommandItemDisplay="TopAndBottom" AutoGenerateColumns="false" EditMode="EditForms">
    <Columns>
      <telerik:GridBoundColumn UniqueName="BirthDate" DataField="BirthDate" Display="false"
        HeaderText="Birth date" DataFormatString="{0:d}" />
      <telerik:GridBoundColumn UniqueName="FirstName" DataField="FirstName" HeaderText="First name" />
      <telerik:GridBoundColumn UniqueName="LastName" DataField="LastName" HeaderText="Last name" />
      <telerik:GridEditCommandColumn UniqueName="EditCommandColumn" />
    </Columns>
  </MasterTableView></telerik:RadGrid>
Not finding the help you need?
Contact Support