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

Conditional Format Radgrid

6 Answers 459 Views
UI for ASP.NET AJAX in ASP.NET MVC
This is a migrated thread and some comments may be shown as answers.
Iain
Top achievements
Rank 1
Iain asked on 14 Jul 2010, 02:31 PM
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


6 Answers, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 14 Jul 2010, 03:06 PM
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
0
Iain
Top achievements
Rank 1
answered on 14 Jul 2010, 04:05 PM
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


0
Dimo
Telerik team
answered on 15 Jul 2010, 06:50 AM
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
0
Iain
Top achievements
Rank 1
answered on 15 Jul 2010, 12:58 PM
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!
0
Accepted
Dimo
Telerik team
answered on 15 Jul 2010, 01:27 PM
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
0
Iain
Top achievements
Rank 1
answered on 15 Jul 2010, 01:53 PM
Doh!!! Well done, no i had missed the handler - runs perfectly now.

Many thanks for your time!
Tags
UI for ASP.NET AJAX in ASP.NET MVC
Asked by
Iain
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Iain
Top achievements
Rank 1
Share this question
or