RadGrid for ASP.NET

Customizing the appearance of the auto-generated Update/Insert/Cancel buttons Send comments on this topic.
Insert/Update/Delete records > How-to > Customizing the appearance of the auto-generated Update/Insert/Cancel buttons

Glossary Item Box

In some scenarios you may want to get a hold on the auto-generated action buttons (update/insert/cancel) inside the auto-generated grid edit form (EditMode = InPlace or EditForms) and modify them a bit without changing the entire layout of the edit form (which is possible with WebUserControl or FormTemplate custom edit form).

Here are the steps to accomplish this task programmatically with several lines of code:

  1. Subscribe to the ItemCreated event of RadGrid
  2. Check whether the currently created item is in edit or insert mode
  3. Find the button of interest by its id (UpdateButton, PerformInsertButton or CancelButton) and alter its setting in par with your preferences

Below is a simple example which changes the text and some of the styles for those buttons:

ASPX/ASCX Copy Code
<rad:RadGrid ID="RadGrid1" runat="server" DataSourceID="AccessDataSource1" AllowSorting="True"
               
Skin="Office2007" GridLines="None" Width="95%">
               
<MasterTableView Width="100%" DataKeyNames="CustomerID" CommandItemDisplay="Top" AutoGenerateColumns="false">
                   
<Columns>
                       
<rad:GridBoundColumn UniqueName="CompanyName" DataField="CompanyName" HeaderText="Company name" />
                       
<rad:GridBoundColumn UniqueName="ContactName" DataField="ContactName" HeaderText="Contact name" />
                       
<rad:GridBoundColumn UniqueName="ContactTitle" DataField="ContactTitle" HeaderText="Contact title" />
                       
<rad:GridEditCommandColumn />
                   
</Columns>
               
</MasterTableView>
</
rad:RadGrid>
<
br />
<
asp:AccessDataSource ID="AccessDataSource1" DataFile="~/Grid/Data/Access/Nwind.mdb"
 
SelectCommand="SELECT TOP 10 CustomerID, CompanyName, ContactName, ContactTitle FROM Customers"
  
runat="server" />


 

VB.NET Copy Code
Protected Sub RadGrid1_ItemCreated(ByVal sender As Object, ByVal e As Telerik.WebControls.GridItemEventArgs) Handles RadGrid1.ItemCreated
        If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then
            If Not e.Item.OwnerTableView.IsItemInserted Then
                Dim updateButton As LinkButton = CType(e.Item.FindControl("UpdateButton"), LinkButton)
                updateButton.Text = "Update record"
                updateButton.Style("font-size") = "12px"
                updateButton.Style("font-weight") = "bold"
                updateButton.Style("color") = "blue"
            Else
                Dim insertButton As LinkButton = CType(e.Item.FindControl("PerformInsertButton"), LinkButton)
                insertButton.Text = "Insert record"
                insertButton.Style("font-size") = "12px"
                insertButton.Style("font-weight") = "bold"
                insertButton.Style("color") = "blue"
            End If
            Dim cancelButton As LinkButton = CType(e.Item.FindControl("CancelButton"), LinkButton)
            cancelButton.Text = "Cancel editing"
            cancelButton.Style("font-size") = "12px"
            cancelButton.Style("font-weight") = "bold"
            cancelButton.Style("color") = "blue"
        End If
End Sub


 

C# Copy Code
protected void RadGrid1_ItemCreated(object sender, Telerik.WebControls.GridItemEventArgs e)
{
if (e.Item is GridEditableItem && e.Item.IsInEditMode)
{
 
if (!e.Item.OwnerTableView.IsItemInserted)
 {
  LinkButton updateButton = (LinkButton)e.Item.FindControl(
"UpdateButton");
  updateButton.Text =
"Update record";
  updateButton.Style[
"font-size"] = "12px";
  updateButton.Style[
"font-weight"] = "bold";
  updateButton.Style[
"color"] = "blue";
 }
 
else
 {
  
LinkButton insertButton = (LinkButton)e.Item.FindControl("PerformInsertButton");
  insertButton.Text =
"Insert record";
  insertButton.Style[
"font-size"] = "12px";
  insertButton.Style[
"font-weight"] = "bold";
  insertButton.Style[
"color"] = "blue";
 }
 LinkButton cancelButton = (LinkButton)e.Item.FindControl(
"CancelButton");
 cancelButton.Text =
"Cancel editing";
 cancelButton.Style[
"font-size"] = "12px";
 cancelButton.Style[
"font-weight"] = "bold";
 cancelButton.Style[
"color"] = "blue";
}
}