6 Answers, 1 is accepted
Check out the following help article which explains how to achieve conditional formatting of Grid cells.
http://www.telerik.com/help/aspnet-ajax/grdconditionalformatting.html
Shinu
Check out the following code to format your cells based on the cell values:
c#:
| protected void RadGrid1_PreRender(object sender, EventArgs e) |
| { |
| foreach (GridColumn col in RadGrid1.MasterTableView.RenderColumns) |
| { |
| foreach (GridDataItem dataItem in RadGrid1.Items) |
| { |
| if ((dataItem)[col.UniqueName].Text == "Text1") |
| { |
| (dataItem)[col.UniqueName].BackColor = System.Drawing.Color.Blue; |
| } |
| } |
| } |
| } |
You can alter the logic according to your requirement.
Thanks
Princy.
OK - after some trial and error the page displays but does nothing...
here's what I've done...
protected void RadGrid2_PreRender(object sender, EventArgs e)
{
foreach (GridColumn col in RadGrid2.MasterTableView.RenderColumns)
{
foreach (GridDataItem dataItem in RadGrid2.Items)
{
if (((dataItem)[col.UniqueName].Text == null))
{
}
else if ((int.Parse((dataItem)[col.UniqueName].Text) > 0) && (int.Parse((dataItem)[col.UniqueName].Text) <= 1))
//else if ((decimal.Parse((dataItem)[col.UniqueName].Text) > 0) && (decimal.Parse((dataItem)[col.UniqueName].Text) <= 1))
{
(dataItem)[col.UniqueName].Text =
string.Format( "{0:00%}");
}
else
{
}
}
}
}
the pivot displays but the numbers don't format. What am i doing wrong?
thanks
Can you apply formatting for the Grid cell as shown below and see whether it is working.
CS:
| (dataItem)["Test"].Text = string.Format("{0:00%}", int.Parse(dataItem[col.UniqueName].Text)); |
Shinu.