I have a Telerik RADGrid with a GridCheckBoxColumn I want to entire row background color to be green if the checkbox value is true. as my first step I was trying to get the value of the checkbox column using the code below.
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
{
CheckBox chkbox = item.FindControl("chkPriority") as CheckBox;
if (chkbox != null && chkbox.Checked)
{
string id_ = item["p_id"].Text;
}
}
}
But this code does not find any of the rows, the value for CheckBox is always null. How can I get those values
I have modified my code and I am now able to get the value of the check box. I can still not figure out how to set the back color of the cell or row. here is the modified code.
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
{
CheckBox chkbox = item["chkPriority"].Controls[0] as CheckBox;
if (chkbox.Checked == true)
{
GridDataItem dataItem = e.Item as GridDataItem;
}
}
}
Good that you figured out how to access the value of the checkbox. To set the color of the entire row I would recommend creating a CSS class that defines the color (and any other styles you want to set). Then apply that class to your rows as needed.
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
GridDataItem item = e.Item as GridDataItem;
CheckBox chkbox = item["chkPriority"].Controls[0] as CheckBox;
if (chkbox.Checked == true)
{
item.CssClass += "MySpecialRow";
}
}
}
Then the CSS class might be defined as:
.MySpecialRow
{
background-color: green;
color: white;
font-weight: bold;
}
Here is a link to a Telerik doc that also describes this and gives an example of how to modify individual columns as well.