Thursday, January 26, 2012

Hide Fields in a AxGroup /AxForm in Enterprise portal

There was a requirement to hide/un-hide the fields within AXGroup according to the setup defined in AX form either to show fields or not as per user.

protected void AxFrmEmployee_PreRender(object sender, EventArgs e)
{
    AxForm frm = this.axFrmEmployee;
   
    for (int i = 0; i < this.AxGroup1.Fields.Count; i++)
    {
        AxBoundField fld = this.AxGroup1.Fields[i] as AxBoundField;
        if ((fld != null) && (fld.Metadata.Name == "TitleId"))
        {
            fld.Visible = (frm.CurrentMode == DetailsViewMode.ReadOnly) ? false : true;
        }
    }
}