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

How to set CssClass or SkinID for GridButtonColumn

3 Answers 496 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rob
Top achievements
Rank 1
Rob asked on 06 Oct 2008, 05:30 PM
I have a grid with a GridButtonColumn, but can't seem to figure out how to set the CssClass or SkinID to the button.  It won't compile when setting the CssClass and doesn't recognize the skin when setting SkinID to the column.  I set the CssClass for the ItemStyle, but it applied the class to the row, not the button.  Please help.

3 Answers, 1 is accepted

Sort by
0
Todd Anglin
Top achievements
Rank 2
answered on 06 Oct 2008, 08:58 PM
Rob-

I think the easiest way to style a button in a column in RadGrid is to use a TemplateColumn. You can then add your button, apply whatever CSS styles you need, and then handle the button's events via the Grid's ItemCommandEvent (interrpeting the CommandName and Args for specific processing). I do not there there is a way to directly edit the styles of the HTML button via properties of the GridButtonColumn. It's a good idea, though. Maybe we can enhance this column to in the future expose a property for skinning the button- something like ButtonCssClass.

Let me know if that will work for you.

-Todd
0
Princy
Top achievements
Rank 2
answered on 07 Oct 2008, 06:43 AM
Hello Rob,

You can set the CsssClass for the button in the ButtonColumn as shown below.
aspx:
<telerik:GridButtonColumn ButtonType="PushButton" Text="Select" UniqueName="ButtonCol"
</telerik:GridButtonColumn> 

cs:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem dataItem = (GridDataItem)e.Item; 
            (dataItem["ButtonCol"].Controls[0] as Button).CssClass = "MyButton"
        } 
   } 

css:
<head runat="server"
  <style type="text/css"
   .MyButton 
   { 
     background-color:Red !important; 
   } 
  </style> 
</head> 

Thanks
Princy.
0
Rob
Top achievements
Rank 1
answered on 07 Oct 2008, 02:05 PM
Princy,

Yep, that worked.  Thanks!

Rob
Tags
Grid
Asked by
Rob
Top achievements
Rank 1
Answers by
Todd Anglin
Top achievements
Rank 2
Princy
Top achievements
Rank 2
Rob
Top achievements
Rank 1
Share this question
or