How to set CssClass or SkinID for GridButtonColumn

4 posts, 0 answers
  1. Rob
    Rob avatar
    115 posts
    Member since:
    Aug 2012

    Posted 06 Oct 2008 Link to this post

    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.
  2. Todd Anglin
    Todd Anglin avatar
    2040 posts
    Member since:
    Aug 2005

    Posted 06 Oct 2008 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 07 Oct 2008 Link to this post

    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.
  5. Rob
    Rob avatar
    115 posts
    Member since:
    Aug 2012

    Posted 07 Oct 2008 Link to this post

    Princy,

    Yep, that worked.  Thanks!

    Rob
Back to Top