Babu Puchakayala
Top achievements
Rank 1
Babu Puchakayala
asked on 20 Sep 2010, 03:27 AM
Hi,
I Created radgrid with the column name "Project Health" ( Unique name is "ProjectHealth"). I can edit this column on popup. Once popup opens they can select text Green or Red or Yellow. (using radcombo box). What i want is when user select the yellow, the text color in the grid should display in yellow and same for both red and green. How to do it. how to do this??
I Created radgrid with the column name "Project Health" ( Unique name is "ProjectHealth"). I can edit this column on popup. Once popup opens they can select text Green or Red or Yellow. (using radcombo box). What i want is when user select the yellow, the text color in the grid should display in yellow and same for both red and green. How to do it. how to do this??
5 Answers, 1 is accepted
0
Accepted
Princy
Top achievements
Rank 2
answered on 20 Sep 2010, 05:28 AM
Hello Babu,
You can do this in OnSelectedIndexChanged event of RadComboBox. Access the column and based on the SelectedItem(color) of RadComboBox, change the text color of column. Sample code is given below for your reference. Change the logic according to your requirement.
ASPX:
C#:
Thanks,
Princy.
You can do this in OnSelectedIndexChanged event of RadComboBox. Access the column and based on the SelectedItem(color) of RadComboBox, change the text color of column. Sample code is given below for your reference. Change the logic according to your requirement.
ASPX:
<
telerik:GridTemplateColumn
>
<
EditItemTemplate
>
<
telerik:RadComboBox
ID
=
"RadComboBox1"
runat
=
"server"
AutoPostBack
=
"True"
OnSelectedIndexChanged
=
"RadComboBox1_SelectedIndexChanged"
>
<
Items
>
<
telerik:RadComboBoxItem
Text
=
"--Select--"
Value
=
"0"
/>
<
telerik:RadComboBoxItem
Text
=
"Yellow"
Value
=
"1"
/>
<
telerik:RadComboBoxItem
Text
=
"Red"
Value
=
"2"
/>
<
telerik:RadComboBoxItem
Text
=
"Green"
Value
=
"3"
/>
</
Items
>
</
telerik:RadComboBox
>
</
EditItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridBoundColumn
DataField
=
"ProjectHealth"
UniqueName
=
"ProjectHealth"
HeaderText
=
"Project Health"
>
</
telerik:GridBoundColumn
>
C#:
protected
void
RadComboBox1_SelectedIndexChanged(
object
o, RadComboBoxSelectedIndexChangedEventArgs e)
{
RadComboBox combo = (RadComboBox)o;
switch
(combo.SelectedItem.Text)
{
case
"Yellow"
:
RadGrid1.MasterTableView.GetColumn(
"ProjectHealth"
).ItemStyle.ForeColor = System.Drawing.Color.Yellow;
break
;
case
"Red"
:
RadGrid1.MasterTableView.GetColumn(
"ProjectHealth"
).ItemStyle.ForeColor = System.Drawing.Color.Red;
break
;
case
"Green"
:
RadGrid1.MasterTableView.GetColumn(
"ProjectHealth"
).ItemStyle.ForeColor = System.Drawing.Color.Green;
break
;
}
}
Thanks,
Princy.
0
Babu Puchakayala
Top achievements
Rank 1
answered on 20 Sep 2010, 01:34 PM
Thanks Princy Thats working great...
0
Babu Puchakayala
Top achievements
Rank 1
answered on 20 Sep 2010, 05:13 PM
I tried another way .. That is also working ... I am just posting here... If anybody wants... Here is the code...
protected
void
gvPjtMnt_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridDataItem)
{
GridDataItem dataItem = e.Item
as
GridDataItem;
TableCell myCell = dataItem[
"ProjectHealth"
];
myCell.Font.Size = 10;
myCell.Font.Bold =
true
;
if
(myCell.Text.Trim() ==
"GREEN"
)
{
myCell.ForeColor = System.Drawing.Color.Green;
}
if
(myCell.Text.Trim() ==
"RED"
)
{
myCell.ForeColor = System.Drawing.Color.Red;
}
if
(myCell.Text.Trim() ==
"YELLOW"
)
{
myCell.ForeColor = System.Drawing.Color.Yellow;
}
}
}
0
Luis
Top achievements
Rank 1
Veteran
answered on 14 Jun 2020, 03:59 PM
And how can I change a cell font color based on the value of another colum?
For example I have a row with
Product - Sold
and I have to change the color of the Product if Sold has 0 or 1 value.
Thank you.
Luis
0
Hello Luis,
You can use the following approach to change the color:
https://www.telerik.com/forums/alternatingitemstyle-5e16887f3085#odVQBomUikiIJfrxeBQrww
And for getting the value of Sold, you can use the DataBinder.Eval approach:
https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/accessing-values-and-controls/server-side/accessing-cells#accessing-raw-field-data-and-key-values
Hope this helps.
Regards,
Eyup
Progress Telerik
Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Our thoughts here at Progress are with those affected by the outbreak.