예제 #1
0
파일: Controls.cs 프로젝트: makamp/asp
        private static HtmlTableCell GetCompleteHtmlTableCell(KeyValuePair <string, int> item, CheckBoxListSettings settings, IList <int> selectedCheckBoxes)
        {
            //Add checkBox
            var htmlTableCheckboxCell = new HtmlTableCell
            {
                InnerHtml = GenerateHtmlMarkupCheckBox(item, settings, selectedCheckBoxes) + GenerateHtmlMarkupLabel(item)
            };

            return(htmlTableCheckboxCell);
        }
예제 #2
0
파일: Controls.cs 프로젝트: makamp/asp
        private static string GenerateHtmlMarkupCheckBox(KeyValuePair <string, int> item, CheckBoxListSettings settings, IList <int> selectedCheckBoxes)
        {
            var tagBuilder = new TagBuilder("input");

            tagBuilder.MergeAttribute("type", "checkbox");
            tagBuilder.MergeAttribute("name", settings.CblName);
            tagBuilder.MergeAttribute("value", item.Value.ToString(CultureInfo.InvariantCulture));

            if (selectedCheckBoxes != null)
            {
                if (selectedCheckBoxes.Contains(item.Value))
                {
                    tagBuilder.MergeAttribute("checked", null);
                }
            }

            return(tagBuilder.ToString(TagRenderMode.SelfClosing));
        }
예제 #3
0
파일: Controls.cs 프로젝트: makamp/asp
        public static MvcHtmlString CheckBoxList(this HtmlHelper helper, IDictionary <string, int> items, IList <int> selectedCheckBoxes, CheckBoxListSettings settings)
        {
            var htmlTable = new HtmlTable();

            var tempTableRow = new HtmlTableRow();

            foreach (var item in items)
            {
                if (tempTableRow.Cells.Count >= ((int)settings.CblRepeatColumns))
                {
                    htmlTable.Rows.Add(tempTableRow);
                    tempTableRow = new HtmlTableRow();
                }

                var tableCell = GetCompleteHtmlTableCell(item, settings, selectedCheckBoxes);
                tempTableRow.Cells.Add(tableCell);
            }

            if (tempTableRow.Cells.Count > 0)
            {
                htmlTable.Rows.Add(tempTableRow);
            }

            string result;

            using (var sw = new StringWriter())
            {
                htmlTable.RenderControl(new HtmlTextWriter(sw));
                result = sw.ToString();
            }
            return(new MvcHtmlString(result));
        }