However, when I click the Save button, in the ItemCommand event, the command is "Update". Should it be "PerformInsert" instead. As a result the InsertCommand procedure is not trigger, but UpdateCommand procedure runs.
May I ask how can I change the default "Save" command for a new row?
Besides, how can I customize the "Save", "Cancel" link?
(I have customized the Edit and Delete link by using Template Columns in the grid.)
Thanks
Raymond
6 Answers, 1 is accepted
Are you using a FormTemplate? If so try setting the CommandName for the Save button as PerformInsert.
ASPX:
| <EditFormSettings EditFormType="template" > |
| <FormTemplate> |
| <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> |
| <asp:LinkButton ID="LinkButton1" runat="server" Text="Save" CommandName="PerformInsert" ></asp:LinkButton> |
| <asp:LinkButton ID="LinkButton2" runat="server" Text="Cancel" CommandName="Cancel" ></asp:LinkButton> |
| </FormTemplate> |
| </EditFormSettings> |
CS:
| protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) |
| { |
| if (e.CommandName == "PerformInsert") |
| { |
| } |
| else if (e.CommandName == "Cancel") |
| { |
| } |
| } |
Thanks
Shinu.
Hi Shinu,
I am not using FormTemplate. It was an in-place edit grid. The "Save" and "Cancel" linkbuttons are generated automatically after clicking the "Add New Record" on the top of the grid. I did not customized these links.
Raymond
Can you check whether the linkbutton in the AutoGenerated Insert Form is Save button on Insert button. Can you send your aspx also.
Shinu.
I've just found that the "Save", "Cancel" linkbuttons are those I created in the GridTemplateColumn. The following is the aspx file.
<%@ Page Language="VB" MasterPageFile="~/Common/MasterPages/management.master"
AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="Manager_BandTypes_Default"
Title="Untitled Page" %>
<%@ 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="cph1" runat="Server">
<telerik:RadAjaxManagerProxy ID="ramp1" runat="server">
</telerik:RadAjaxManagerProxy>
<h4>
- Watch Band Type Maintenance -</h4>
<asp:Panel ID="pnlGrid" runat="server">
<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" AllowMultiRowEdit="false"
AutoGenerateDeleteColumn="false" AutoGenerateColumns="false" AutoGenerateEditColumn="False"
AllowMultiRowSelection="false" DataSourceID="sqlBandType" GridLines="None"
BorderStyle="None" BackColor="White" Skin="Telerik">
<MasterTableView CommandItemDisplay="Top" DataKeyNames="BandTypeID" DataSourceID="sqlBandType"
BorderColor="Gray" BorderWidth="1" BorderStyle="Solid" Name="MasterBandType"
EditMode="InPlace">
<DetailTables>
<telerik:GridTableView runat="server" DataKeyNames="BandTypeID" DataSourceID="sqlBandTypeResx"
BorderColor="Gray" BorderWidth="1" BorderStyle="Solid" EditMode="InPlace"
Name="DetailBandTypeResx">
<ParentTableRelation>
<telerik:GridRelationFields DetailKeyField="BandTypeID" MasterKeyField="BandTypeID" />
</ParentTableRelation>
<RowIndicatorColumn Visible="False">
</RowIndicatorColumn>
<ExpandCollapseColumn Resizable="False" Visible="False">
<HeaderStyle Width="10px" />
</ExpandCollapseColumn>
<Columns>
<telerik:GridTemplateColumn UniqueName="BandTypeID_and_CultureTag" Visible="false">
<EditItemTemplate>
<asp:Label ID="BandTypeResx_ID" runat="server" Text='<%# Eval("BandTypeId") %>'></asp:Label>
<asp:Label ID="BandTypeResx_CultureTag" runat="server" Text='<%# Eval("CultureTag") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label runat="server" Text='<%# Eval("BandTypeId") %>'></asp:Label>
<asp:Label runat="server" Text='<%# Eval("CultureTag") %>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn DataField="CultureDesc" HeaderText="Language"
ReadOnly="true" UniqueName="CultureDesc">
<ItemStyle Width="120px" />
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn DataField="Description" HeaderText="Localized Description"
UniqueName="LocalizedDesc">
<HeaderStyle Width="420px" />
<EditItemTemplate>
<asp:TextBox ID="LocalizedDescTextBox" runat="server" MaxLength="100" Text='<%# Bind("Description") %>'
Width="400px"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="LocalizedDescLabel" runat="server" Text='<%# Eval("Description") %>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn>
<ItemStyle Width="100px" HorizontalAlign="Center" />
<ItemTemplate>
<asp:LinkButton ID="lnkEditDetail" runat="server" CommandName="Edit" Text="Edit" />
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="lnkUpdateDetail" runat="server" CommandName="Update"
Text="Update" />
|
<asp:LinkButton ID="lnkCancelDetail" runat="server" CommandName="Cancel"
Text="Cancel" />
</EditItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
<EditFormSettings>
<PopUpSettings ScrollBars="None" />
</EditFormSettings>
</telerik:GridTableView>
</DetailTables>
<NoRecordsTemplate>
No records
</NoRecordsTemplate>
<RowIndicatorColumn Visible="False">
</RowIndicatorColumn>
<ExpandCollapseColumn Resizable="False">
<HeaderStyle Width="10px" />
</ExpandCollapseColumn>
<ItemStyle Height="25px" />
<AlternatingItemStyle Height="25px" />
<Columns>
<telerik:GridTemplateColumn DataField="BandTypeID" DataType="System.Int64"
HeaderText="ID" SortExpression="BandTypeID" UniqueName="BandTypeID">
<HeaderStyle Width="20px" />
<EditItemTemplate>
<asp:Label ID="BandTypeIDLabel" runat="server" Text='<%# Eval("BandTypeID") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="BandTypeIDLabel" runat="server" Text='<%# Eval("BandTypeID") %>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn DataField="DefaultDesc" HeaderText="Default Description"
SortExpression="DefaultDesc" UniqueName="DefaultDesc">
<HeaderStyle Width="450px" />
<EditItemTemplate>
<asp:TextBox ID="DefaultDescTextBox" runat="server" MaxLength="100" Text='<%# Bind("DefaultDesc") %>'
Width="420px"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="DefaultDescLabel" runat="server" Text='<%# Eval("DefaultDesc") %>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Active" UniqueName="TemplateColumn">
<HeaderStyle Width="50px" HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
<EditItemTemplate>
<asp:CheckBox ID="ActiveCheckBox" Width="40px" Checked='<%# Bind("Active") %>'
runat="server" />
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="ActiveLabel" runat="server" Text='<%# IIF(Eval("Active"), "Yes", "No") %>'
Width="40px"></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn>
<ItemStyle Width="100px" HorizontalAlign="Center" />
<ItemTemplate>
<asp:LinkButton ID="lnkEditMaster" runat="server" CommandName="Edit" Text="Edit" />
|
<asp:LinkButton ID="lnkDeleteMaster" runat="server" CommandName="Delete"
Text="Delete" OnClientClick="return confirm('Are you sure to delete this Band Type?')" />
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="lnkAddNewMaster" runat="server" CommandName="PerformInsert"
Text="Insert" />
<asp:LinkButton ID="lnkUpdateMaster" runat="server" CommandName="Update"
Text="Save" />
|
<asp:LinkButton ID="lnkCancelMaster" runat="server" CommandName="Cancel"
Text="Cancel" />
</EditItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
<EditFormSettings>
<PopUpSettings ScrollBars="None" />
</EditFormSettings>
<PagerStyle Mode="NumericPages" Position="TopAndBottom" />
</MasterTableView>
</telerik:RadGrid>
</asp:Panel>
<asp:SqlDataSource ID="sqlBandType" runat="server" ConnectionString="<%$ ConnectionStrings:cwConn %>"
SelectCommand="SELECT * FROM [BandType] ORDER BY [DefaultDesc]"></asp:SqlDataSource>
<asp:SqlDataSource ID="sqlBandTypeResx" runat="server" ConnectionString="<%$ ConnectionStrings:cwConn %>"
SelectCommand="SELECT B.BandTypeID, B.CultureTag, B.Description, C.Description AS CultureDesc
FROM BandTypeResx B, Culture C
WHERE B.BandTypeID=@BandTypeID AND B.CultureTag=C.CultureTag
ORDER BY B.BandTypeID, C.Description">
<SelectParameters>
<asp:SessionParameter Name="BandTypeID" SessionField="@BandTypeID" />
</SelectParameters>
</asp:SqlDataSource>
</asp:Content>
Thanks
As a workaround, I created an extra LinkButton in the GridTemplateColumn as "Insert" with the "PerformInsert" commandname. Then, during the RadGrid.PreRender event, enable or disable the visibility of the "Insert" and "Save" Linkbutton accordingly.
Is it the proper way to do, or there is some better method can be used?
Thanks
Hi Raymond,
Try to use the GridEditCommandColumn for editing purpose so the default Update and Cancel button will appear on clicking the Edit button.
ASPX:
| <telerik:GridEditCommandColumn > |
| </telerik:GridEditCommandColumn> |
You can also go through the following help articles.
Edit forms
Inserting values using UserControl/FormTemplate
Princy.