protected void GridRelated_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { var item = new ProductItem(); item = (ProductItem)e.Row.DataItem; if (item.IsThreadRoot) lastRowDataboundRoot = e.Row; else { if (lastRowDataboundRoot != null) e.Row.RowState = lastRowDataboundRoot.RowState; //keeps same style of thread root } if (item.Id == base.CurrentId) { e.Row.Visible = false; } var pman = new ProductItemsManager(); var relatedIds = pman.GetRelatedItems(CurrentId).Select(x => x.Id); CheckBox chkRow = (CheckBox)e.Row.FindControl("chkRow"); if (relatedIds.Contains(item.Id)) { chkRow.Checked = true; } } }