예제 #1
0
        /// <summary>
        /// Iterates a control and its children controls, ensuring they are all LiteralControls
        /// <remarks>
        /// Only LiteralControl can call RenderControl(System.Web.UI.HTMLTextWriter htmlWriter) method. Otherwise 
        /// a runtime error will occur. This is the reason why this method exists.
        /// </remarks>
        /// </summary>
        /// <param name="control">The control to be cleared and verified</param>
        private void RecursiveClear(Control control)
        {

            //Clears children controls
            for (int i = control.Controls.Count - 1; i >= 0; i--)
            {
                RecursiveClear(control.Controls[i]);
            }

            string columnName = string.Empty;
            Object controlTemp = (object)control;

            if (control.Parent is DataControlFieldCell)
            {
                columnName = ((DataControlFieldCell)control.Parent).ContainingField.HeaderText;
            }
            ExcelFormatEventArgs args = new ExcelFormatEventArgs();
            args.ColumnName = columnName;
            args.Control = control;

            if (args.Cancel) return;

            OnBeforeFormat(args);

            if (control is Repeater)
            {
                control.Parent.Controls.Remove(control);                
            }            
            //If it is a LinkButton, convert it to a LiteralControl
            else if (control is LinkButton)
            {
                LiteralControl literal = new LiteralControl();
                control.Parent.Controls.Add(literal);
                literal.Text = ((LinkButton)control).Text;
                control.Parent.Controls.Remove(control);
            }
            //We don't need a button in the excel sheet, so simply delete it
            else if (control is Button)
            {
                control.Parent.Controls.Remove(control);
            }
            // Replace image with 'o' char
            else if (control is Image)
            {
                if (((Image)control).Visible)
                {
                    control.Parent.Controls.Add(new LiteralControl("<span style='font-size:8px;'>o</span>"));
                }
                control.Parent.Controls.Remove(control);
            }
            //If it is a ListControl, copy the text to a new LiteralControl
            else if (control is ListControl)
            {
                LiteralControl literal = new LiteralControl();
                control.Parent.Controls.Add(literal);
                try
                {
                    literal.Text = ((ListControl)control).SelectedItem.Text;
                }
                catch
                {
                }
                control.Parent.Controls.Remove(control);
            }
            //If it is a Hyperlink, convert it to a LiteralControl
            else if (control is HyperLink)
            {
                LiteralControl literal = new LiteralControl();
                control.Parent.Controls.Add(literal);
                literal.Text = ((HyperLink)control).Text;
                control.Parent.Controls.Remove(control);
            }
            //You may add more conditions when necessary

            Object controlTemp1 = (object)control;
            args.Formatted = controlTemp.Equals(controlTemp1);
            OnAfterFormat(args);
            return;
        }
예제 #2
0
 /// <summary>
 /// Called when a control is in the scope to be formated
 /// </summary>
 /// <param name="e">The ExcelFormatEventArgs instance containing the event data.</param>
 protected virtual void OnAfterFormat(ExcelFormatEventArgs e)
 {
     if (null != AfterFormat)
     {
         AfterFormat(this, e);
     }
 }
예제 #3
0
 /// <summary>
 /// Occures before control is formatted
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void exp_BeforeFormat(object sender, ExcelFormatEventArgs e)
 {
     if (ExcelBeforeFormat != null) ExcelBeforeFormat(sender, e);
 }
예제 #4
0
 /// <summary>
 /// Called when a control is in the scope to be formated
 /// </summary>
 /// <param name="e">The ExcelFormatEventArgs instance containing the event data.</param>
 protected virtual void OnBeforeFormat(ExcelFormatEventArgs e)
 {
     if (null != BeforeFormat)
     {
         BeforeFormat(this, e);
     }
 }
예제 #5
0
 /// <summary>
 /// Occures after control is formatted
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void exp_AfterFormat(object sender, ExcelFormatEventArgs e)
 {
     if (ExcelAfterFormat != null) ExcelAfterFormat(sender, e);
 }