Conditional Format Radgrid

Thread is closed for posting
7 posts, 1 answers
  1. Iain
    Iain avatar
    8 posts
    Member since:
    Jul 2010

    Posted 14 Jul 2010 Link to this post

    Hi,

    I would like to develop the ability to conditional format a radgrid based upon a value within a field.

    My radgrid data is built on the NeedDataSource and is pretty simple. I have done a quick sweep of google for conditional formatting, but i cant seem to find a simplistic answer on how to achieve it.

    This is my senario.

    I have a column in the grid called "Status" i want to format the background of rows with a status of "R"  to a shade of red.

    All other status' need not deviate from the standard formatting.

    Can some offer a bit of code or advice on how to achive this?

    Many Thanks


  2. Dimo
    Admin
    Dimo avatar
    8330 posts

    Posted 14 Jul 2010 Link to this post

    Hi Iain,

    Please refer to:

    http://www.telerik.com/help/aspnet-ajax/grdconditionalformatting.html

    Best wishes,
    Dimo
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Iain
    Iain avatar
    8 posts
    Member since:
    Jul 2010

    Posted 14 Jul 2010 Link to this post

    Hi,

    Thanks for your reply - i have had a good read through and attempted to apply the code:

    protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
      {
          if (e.Item is GridDataItem)
          {
              GridDataItem dataItem = e.Item as GridDataItem;
              if (dataItem["Status"].Text == "R")
                  dataItem.CssClass = "RefundClass";
          }
      }

    I have applied the office 2007 skin to the radgrid, hence using this option. i have also added to my style sheet:

    .RefundClass
    {
      background-color: aqua;
      font-size: 16px;
      font-family: Arial;
    }

    When I open the page, none of the rows are formatted in the .refundclass colours.

    Can you see an error in my code here?

    Many thanks


  5. Dimo
    Admin
    Dimo avatar
    8330 posts

    Posted 15 Jul 2010 Link to this post

    Hi Iain,

    Your CSS rule uses a selector with specificity of 10. The row styles in the RadGrid skin use higher specificity (20), so you should increase yours as well. Please refer to:

    http://blogs.telerik.com/dimodimov/posts/08-06-17/how_to_override_styles_in_a_radcontrol_for_asp_net_ajax_embedded_skin.aspx

    For example, this will work (specificity 21):

    div.RadGrid .RefundClass
    {
        ....   
    }


    All the best,
    Dimo
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. Iain
    Iain avatar
    8 posts
    Member since:
    Jul 2010

    Posted 15 Jul 2010 Link to this post

    Hi,

    thanks for the help so far - im afraid ive still got a bit of a pickle over this one!!

    It seems that this never gets called - therefore not getting my conditional formatting!!

     

    protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)

     



    I have put a breakpoint in the first line of code after this line and when i run the page, the code never breaks (as if this void is never run).

    Am i missing something somewhere??

    Many Thanks for your continued help!
  7. Answer
    Dimo
    Admin
    Dimo avatar
    8330 posts

    Posted 15 Jul 2010 Link to this post

    Hi Iain,

    Have you attached the handler ?

    <telerik:RadGrid  OnItemDataBound="RadGrid1_ItemDataBound"  />

    If you need further assistance, please send a complete runnable page for us to inspect.

    Best wishes,
    Dimo
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  8. Iain
    Iain avatar
    8 posts
    Member since:
    Jul 2010

    Posted 15 Jul 2010 Link to this post

    Doh!!! Well done, no i had missed the handler - runs perfectly now.

    Many thanks for your time!
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017