Monday, February 2, 2015

Replace checkboxes for Boolean values with images in nonedit mode at a DevExpress 13.1.9 grid.

Use the .HtmlDataCellPrepared event like so:

private void MyGrid_HtmlDataCellPrepared(object sender,
      ASPxGridViewTableDataCellEventArgs e)
{
   if (e.DataColumn.FieldName == "Admin")
   {
      e.Cell.Controls.Clear();
      if ((bool)e.CellValue)
      {
         var activeImage = new ASPxImage()
         {
            ImageUrl = "/whatever.png"
         };
         e.Cell.Controls.Add(activeImage);
      } else {
         var activeImage = new ASPxImage()
         {
            ImageUrl = "/somethingelse.png"
         };
         e.Cell.Controls.Add(activeImage);
      }
   }
}

No comments:

Post a Comment