示例#1
0
        /// <summary>
        /// Creates a list of checkbox to allow the user to select multiple values. Values are posted to the server as 1,2,3 etc.
        /// </summary>
        /// <param name="name">The name to assign to the checkbox inputs</param>
        /// <param name="items">The list of items for the list</param>
        /// <param name="tabIndex">The tab index for the items</param>
        /// <returns>
        ///         Span with the id of [name]Container that encompases the whole list. 
        ///         A span item for each checkbox with the class checkboxContainer assigned. A [name]_chk_[i] for each checkbox input to be rendered. 
        ///         A hidden input field for each checkbox item, when it is submitted to the server, it will be the list of values separated by commas
        /// </returns>
        public TagBuilder CheckboxList(string name, SelectItemList items, int tabIndex)
        {

            var parent = new TagBuilder("span").ID(name + "Container");

            var i = 0;
            foreach (var item in items.ToArray())
            {

                var checkboxId = name + "_chk_" + i;
                var checkboxName = name + "_chk";
                var hiddenId = name + i;
                var hiddenName = name;

                // Add item container
                var checkboxContainer = parent.AddChild("span").AddClass("checkboxContainer");

                // Add the radio input
                checkboxContainer.AddChild("input").type("checkbox")
                                    .Name(checkboxName)
                                    .ID(checkboxId)
                                    .value(item.Value)
                                    .@checked(item.Selected)
                                    .tabIndex(tabIndex, -1)
                                    .onclick("jQuery('#" + hiddenId + "').val((this.checked ? $(this).val() : ''));");

                // Add the hidden field that will hold the value (default the value if the item is selected)
                checkboxContainer.AddChild("input").type("hidden")
                                 .Name(hiddenName)
                                 .ID(hiddenId)
                                 .valueIf(item.Selected, item.Value);

                // Add the radio label
                checkboxContainer.AddChild("label").@for(name + i).AddClass("checkboxLabel").InnerText(item.Text);

                // Make the id unique
                i += 1;
            }

            return parent;
        }
示例#2
0
        /// <summary>
        /// Create a radio list
        /// </summary>
        /// <param name="name">Element Name</param>
        /// <param name="items">Option list</param>
        /// <param name="tabIndex">The tabIndex to assign to the radio item</param>
        /// <param name="addCssClassToInput">Add a CSS class to every input created</param>
        /// <param name="addCssClassToLabel">Add a css class to every label for every input</param>
        /// <param name="addCssClassToRow">This will add a set of css classes to the the row contianing the the input and label</param>
        /// <returns>A TagBuilder class to continue to create the tag by adding attr classes etc.</returns>
        public TagBuilder RadioList(string name, SelectItemList items, int tabIndex, string addCssClassToInput, string addCssClassToLabel, string addCssClassToRow)
        {
            var parent = new TagBuilder("span").ID(name + "Container");
            if (string.IsNullOrEmpty(addCssClassToInput)) addCssClassToInput = "";
            if (string.IsNullOrEmpty(addCssClassToLabel)) addCssClassToLabel = "";
            if (string.IsNullOrEmpty(addCssClassToRow)) addCssClassToRow = "";

            var i = 0;
            foreach (var item in items.ToArray())
            {

                // Add radioItem
                var radioItem = parent.AddChild("span").AddClass("radioItem " + addCssClassToRow);

                // Add the radio input
                var radio = radioItem.AddChild("input").Name(name).type("radio").value(item.Value).ID(name + i).AddClass(addCssClassToInput);
                // Mark as selected
                if (item.Selected)
                    radio.@checked(true);

                // Set the tabIndex
                if (tabIndex > -1) radio.tabIndex(tabIndex);

                // Add the radio label
                radioItem.AddChild("label").@for(name + i).AddClass("radioLabel " + addCssClassToLabel).InnerText(item.Text);

                // Make the id unique
                i += 1;
            }

            return parent;
        }
示例#3
0
 /// <summary>
 /// Create an image tag sorrounded by an anchor tag.
 /// </summary>
 /// <param name="src">The source of the image to use</param>
 /// <returns>A TagBuilder class to continue to create the tag by adding attr classes etc.</returns>
 public TagBuilder ImageLink(string src)
 {
     var lnk = new TagBuilder("a").href("javascript:void(0);").AddClass("pointer");
     lnk.AddChild("img").src(src).AddClass("pointer");
     return lnk;
 }
示例#4
0
        /// <summary>
        /// Create a radio list
        /// </summary>
        /// <param name="name">Element Name</param>
        /// <param name="items">Option list</param>
        /// <param name="tabIndex">The tabIndex to assign to the radio item</param>
        /// <returns>A TagBuilder class to continue to create the tag by adding attr classes etc.</returns>
        public TagBuilder BoundRadioList(string name, SelectItem[] items, int tabIndex)
        {
            var parent = new TagBuilder("span").ID(name + "Container");

            var i = 0;
            foreach (var item in items)
            {

                // Add radioItem
                var radioItem = parent.AddChild("span").AddClass("radioItem");

                // Add the radio input
                var radio = radioItem.AddChild("input").Name(name).type("radio").value(item.Value).ID(name + i).bindChecked(name);

                // Set the tabIndex
                if (tabIndex > -1) radio.tabIndex(tabIndex);

                // Add the radio label
                radioItem.AddChild("label").@for(name + i).AddClass("radioLabel").InnerText(item.Text);

                // Make the id unique
                i += 1;
            }

            return parent;
        }
示例#5
0
        /// <summary>
        /// Creates an anchor tag that surrounds two divs that can be floated together to form the sliding door technique.
        /// </summary>
        /// <param name="Title">This is the text that will appear inside the link</param>
        /// <param name="leftCSSClass">This is the CSS class assigned to the left part of the sliding door technique</param>
        /// <param name="rightCSSClass">This is the CSS class assigned to the right part of the sliding door technique</param>        
        public TagBuilder LinkWithSlidingDoor(string Title, string leftCSSClass, string rightCSSClass)
        {
            var tb = new TagBuilder("a").href("javascript:void(0);").AddClass("nouline");

            tb.AddChild("div").text(Title).AddClass(leftCSSClass)
                .Parent
              .AddChild("div").AddClass(rightCSSClass);

            return tb;

        }