Example #1
0
        private static string GetControlValue(Control input, object extraData)
        {
            var textBox = input as TextBox;

            if (textBox != null)
            {
                return(textBox.Text);
            }

            var checkBox = input as CheckBox;

            if (checkBox != null)
            {
                return(checkBox.Checked ? "true" : "false");
            }

            var radioList = input as RadioButtonList;

            if (radioList != null)
            {
                return(radioList.SelectedValue);
            }

            var listBox = input as ListBox;

            if (listBox != null)
            {
                return((bool)extraData
                    ? ControlUtils.SelectedListItemValuesToInt(listBox.Items).ToString()
                    : ControlUtils.ConcatenateSelectedListItemValues(listBox.Items));
            }

            var dropDownList = input as DropDownList;

            if (dropDownList != null)
            {
                return(dropDownList.SelectedItem.Value);
            }

            var checkBoxList = input as CheckBoxList;

            if (checkBoxList != null)
            {
                ListItemCollection boxes = checkBoxList.Items;

                int postedJobValues = 0;

                for (int i = 0; i < boxes.Count; i++)
                {
                    // The enum stores things in power of two,
                    // so for each item we get to, we take its relative position
                    // as a power of two
                    if (boxes[i].Selected)
                    {
                        postedJobValues += (int)Math.Pow(2, i);
                    }
                }

                return(postedJobValues.ToString());
            }

            var hiddenField = input as HiddenField;

            if (hiddenField != null)
            {
                return(hiddenField.Value);
            }

            throw new ArgumentException("Unsupported type of input control: " + input.GetType().FullName, "input");
        }