CommandColumn - Where can we set Button's Text

2 posts, 0 answers
  1. Majid Darab
    Majid Darab avatar
    112 posts
    Member since:
    Dec 2009

    Posted 23 Mar 2019 Link to this post

    Please take a look at this example : 

    Change the appearance of the buttons in GridViewCommandColumn

    I want to create buttons with `Delete` text of every buttons.

    But when i create a CommandColumn in GridView text of every button is empty.

    Where can we set Button's Text?


    Thanks in advance

  2. Hristo
    Hristo avatar
    1520 posts

    Posted 26 Mar 2019 Link to this post

    Hi Majid,

    Please make sure that you have subscribed the grid to the CellFormatting event. You can also check my code snippet below: 
    public partial class RadForm1 : Telerik.WinControls.UI.RadForm
        public RadForm1()
            this.radGridView1.DataSource = this.GetData();
            this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
            GridViewCommandColumn col = new GridViewCommandColumn("Command");
            this.radGridView1.CellFormatting += this.RadGridView1_CellFormatting;
        private void RadGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
            if (e.CellElement.ColumnInfo is GridViewCommandColumn)
                // This is how we get the RadButtonElement instance from the cell
                RadButtonElement button = (RadButtonElement)e.CellElement.Children[0];
                if (e.CellElement.RowInfo.Cells["Id"].Value != null)
                    int id = (int)e.CellElement.RowInfo.Cells["Id"].Value;
                    if (id % 2 == 0)
                        button.Text = "Disabled";
                        button.Enabled = false;
                        button.Text = "Enabled";
                        button.Enabled = true;
        private object GetData()
            DataTable dt = new DataTable();
            dt.Columns.Add("Id", typeof(int));
            dt.Columns.Add("Name", typeof(string));
            dt.Columns.Add("Date", typeof(DateTime));
            for (int i = 0; i < 100; i++)
                dt.Rows.Add(i, "Name " + i, DateTime.Now.AddDays(1));
            return dt;

    I have also attached a screenshot showing the result. 

    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