Example #1
0
        /// <summary>
        /// Occurs when cell binds to the field value
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void OnDataBindField(object sender, EventArgs e)
        {
            DataControlFieldCell cell = (DataControlFieldCell)sender;
            HyperLink            link = (HyperLink)cell.Controls[0];
            object controlContainer   = cell.BindingContainer;
            object item = DataBinder.GetDataItem(controlContainer);

            // check if the complex type is used
            if (DataTextField.Length > 0 && DataContainer.Length > 0)
            {
                //string[] values = DataTextField.Split(new char[] { '.' });
                item = DataBinder.Eval(item, this.DataContainer);
                if (item == null)
                {
                    return;
                }
            }

            if (DataTextField.Length > 0)
            {
                if (dataTextFieldProperties == null)
                {
                    SetupProperties(item);
                }
                object[] dataTextValues = new object[DataTextField.Split(',').Length];

                for (int n = 0; n < dataTextValues.Length; n++)
                {
                    dataTextValues[n] = dataTextFieldProperties[n].GetValue(item);
                }
                link.Text = FormatDataTextValue(dataTextValues);
            }

            string[] urlFields = DataNavigateUrlFields;
            if (urlFields.Length > 0)
            {
                if (urlProperties == null)
                {
                    SetupProperties(item);
                }
                object[] dataUrlValues = new object[urlFields.Length];

                for (int n = 0; n < dataUrlValues.Length; n++)
                {
                    dataUrlValues[n] = urlProperties[n].GetValue(item);
                }
                link.NavigateUrl = FormatDataNavigateUrlValue(dataUrlValues);
            }
        }
Example #2
0
        /// <summary>
        /// Is used to set properties of the HyperLinkField
        /// </summary>
        /// <param name="controlContainer"></param>
        void SetupProperties(object controlContainer)
        {
            PropertyDescriptorCollection props = TypeDescriptor.GetProperties(controlContainer);

            if (DataTextField.Length > 0)
            {
                string[] dataFields = DataTextField.Split(',');
                if (dataFields.Length > 0)
                {
                    dataTextFieldProperties = new PropertyDescriptor[dataFields.Length];
                    for (int n = 0; n < dataFields.Length; n++)
                    {
                        PropertyDescriptor prop = props[dataFields[n]];
                        if (prop == null)
                        {
                            throw new InvalidOperationException(string.Format("Property '{0}' not found in object of type {1}", dataFields[n], controlContainer.GetType()));
                        }
                        dataTextFieldProperties[n] = prop;
                    }
                }
            }

            string[] urlFields = DataNavigateUrlFields;
            if (urlFields.Length > 0)
            {
                urlProperties = new PropertyDescriptor[urlFields.Length];
                for (int n = 0; n < urlFields.Length; n++)
                {
                    PropertyDescriptor prop = props[urlFields[n]];
                    if (prop == null)
                    {
                        throw new InvalidOperationException(string.Format("Property '{0}' not found in object of type {1}", urlFields[n], controlContainer.GetType()));
                    }
                    urlProperties[n] = prop;
                }
            }
        }