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

change command button color

1 Answer 669 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jhjang
Top achievements
Rank 1
Jhjang asked on 20 Mar 2015, 04:31 AM
Hi

I changed command button color using GridViewCommandColumn

The below code is added in CommandCellClick event handler

cell.CommandButton.ButtonFillElement.BackColor = frmColor.Color;

this code changed the color, but when I add a new row, the color move to new row.

And the cell which I changed the color of return default color.

Could you let me know how I can change command button color in cell?

1 Answer, 1 is accepted

Sort by
0
Ralitsa
Telerik team
answered on 20 Mar 2015, 02:07 PM
Hi Jaeyong,

Thank you for contacting us. 

The CommandCellClick event is fired when you click on the button. If you need to change the appearance of the buttons that appear in the cells of the GridViewCommandColumn, it is better to subscribe to the CellFormatting event and change the BackColor property to desire color. Please take a look at the following code snippet which demonstrates how to achieve it: 
if (e.CellElement.ColumnInfo is GridViewCommandColumn)
{
    GridCommandCellElement element = (GridCommandCellElement)e.CellElement;
    element.CommandButton.ButtonFillElement.BackColor = Color.GreenYellow;
    element.CommandButton.ButtonFillElement.GradientStyle = Telerik.WinControls.GradientStyles.Solid;
}

More information about changing appearance of the grid cells can be found at Formatting Cells article, section Example 3: Change the appearance of the buttons in GridViewCommandColumn. 

In attachments you can find the sample demo. 

If this is not what you want to achieve, I would kindly ask you to send me a more detailed explanation what is your case and the code snippet from handler of the CommandCellClick event. 

Let me know if I can assist you further.

Regards,
Ralitsa
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
GridView
Asked by
Jhjang
Top achievements
Rank 1
Answers by
Ralitsa
Telerik team
Share this question
or