How to show/hide user control in transformation in according to value of field of displayed item

Martin Dobsicek asked on October 4, 2009 07:24

How to show/hide user control in transformation in according to value of field of displayed item

Correct Answer

Martin Dobsicek answered on October 4, 2009 07:24

You can use sample code bellow to find out value of field (in this case called 'Name') of document currently processed by repeater and show/hide the custom user control accordingly (in this case show it if name is 'Kentico' and hide it otherwise):

<script runat="server">
      protected override void OnInit(EventArgs e)
      {
        base.OnInit(e);
        if (this.Parent is IDataItemContainer)
        {
          IDataItemContainer cont = this.Parent as IDataItemContainer;
          if (cont != null)
          {
            System.Data.DataRowView drv = (System.Data.DataRowView)cont.DataItem as System.Data.DataRowView;
            if (drv != null)
            {
                this.myUserControl.Visible = (drv["Name"].ToString() == "Kentico");
            }
            else
            {
              Response.Write("Error: DataRowView is null");
            }
          }
          else
          {
            Response.Write("Error: IDataItemContainer is null");
          }
        }
      }
</script>

0 votesVote for this answer Unmark Correct answer

   Please, sign in to be able to submit a new answer.