Exemplo n.º 1
0
        /// <include file='doc\XhtmlBasicListAdapter.uex' path='docs/doc[@for="XhtmlListAdapter.RenderList"]/*' />
        protected virtual void RenderList(XhtmlMobileTextWriter writer)
        {
            MobileListItemCollection items = Control.Items;

            if (items.Count == 0)
            {
                return;
            }

            ListDecoration decoration = Control.Decoration;

            // Review: Consider replacing switch.
            switch (decoration)
            {
            case ListDecoration.Bulleted:
                RenderBulletedList(writer);
                break;

            case ListDecoration.Numbered:
                RenderNumberedList(writer);
                break;

            default:
                if (!Device.Tables)
                {
                    RenderUndecoratedList(writer);
                    return;
                }
                RenderTableList(writer);
                break;
            }
        }
        public override void OnPreRender(EventArgs e)
        {
            int firstSelectedIndex;
            MobileListItemCollection items = Control.Items;
            int count = items.Count;

            for (firstSelectedIndex = 0; firstSelectedIndex < count; firstSelectedIndex++)
            {
                if (items[firstSelectedIndex].Selected)
                {
                    break;
                }
            }
            if (firstSelectedIndex < count)
            {
                StringBuilder ivalue = new StringBuilder();
                ivalue.Append((firstSelectedIndex + 1).ToString());
                if (Control.IsMultiSelect)
                {
                    for (int i = firstSelectedIndex + 1; i < count; i++)
                    {
                        if (items[i].Selected)
                        {
                            ivalue.Append(";");
                            ivalue.Append((i + 1).ToString());
                        }
                    }
                }

                _ivalue = ivalue.ToString();
            }
            else
            {
                String defaultValue = null;

                if (!Control.IsMultiSelect)
                {
                    // 1 is the first index of a single selection list
                    defaultValue = "1";
                }
                else if (Device.CanRenderSetvarZeroWithMultiSelectionList)
                {
                    // 0 means no items have been selected, for MultiSelect case
                    defaultValue = "0";
                }

                if (defaultValue != null)
                {
                    _ivalue = defaultValue;
                }
            }
        }
        public override void Render(WmlMobileTextWriter writer)
        {
            MobileListItemCollection items = Control.Items;
            int count = items.Count;

            if (count == 0)
            {
                return;
            }

            writer.EnterLayout(Style);
            bool crossPagePost = Control.Form.Action != String.Empty;

            if (crossPagePost)
            {
                if (_ivalue != null)
                {
                    String formVariable = ClientPrefix + Control.ClientID;
                    writer.AddFormVariable(formVariable, _ivalue, false);
                    // does not render _ivalue if null or form variables written.
                    writer.RenderBeginSelect(Control.ClientID, formVariable, _ivalue, Control.Title, Control.IsMultiSelect);
                }
                else // _ivalue == null
                {
                    writer.RenderBeginSelect(Control.ClientID, null, null, Control.Title, Control.IsMultiSelect);
                }
            }
            else // !crossPagePost
            {
                if (_ivalue != null)
                {
                    writer.AddFormVariable(Control.ClientID, _ivalue, false);
                }
                // does not render _ivalue if null or form variables written.
                writer.RenderBeginSelect(null, Control.ClientID, _ivalue, Control.Title, Control.IsMultiSelect);
            }

            foreach (MobileListItem item in items)
            {
                if (crossPagePost)
                {
                    writer.RenderSelectOption(item.Text, item.Value);
                }
                else
                {
                    writer.RenderSelectOption(item.Text);
                }
            }
            writer.RenderEndSelect(Control.BreakAfter);
            writer.ExitLayout(Style);
        }
Exemplo n.º 4
0
        /// <include file='doc\WmlListAdapter.uex' path='docs/doc[@for="WmlListAdapter.Render"]/*' />
        public override void Render(WmlMobileTextWriter writer)
        {
            if (Control.HasControls())
            {
                writer.BeginCustomMarkup();
                RenderChildren(writer);
                writer.EndCustomMarkup();
                return;
            }

            int pageStart = Control.FirstVisibleItemIndex;
            int pageSize  = Control.VisibleItemCount;

            if (pageSize == 0)
            {
                return;
            }

            MobileListItemCollection items = Control.Items;

            if (items.Count == 0)
            {
                return;
            }

            bool itemsAsLinks  = Control.ItemsAsLinks;
            bool hasCmdHandler = Control.HasItemCommandHandler;

            writer.EnterStyle(Style);
            for (int i = 0; i < pageSize; i++)
            {
                MobileListItem item = items[pageStart + i];

                if (itemsAsLinks)
                {
                    RenderLink(writer, item.Value, null, false, false, item.Text, true);
                }
                else if (hasCmdHandler)
                {
                    RenderPostBackEvent(writer, item.Index.ToString(CultureInfo.InvariantCulture), null, true, item.Text, true);
                }
                else
                {
                    writer.RenderText(item.Text, true);
                }
            }
            writer.ExitStyle(Style);
        }
        /// <include file='doc\HtmlSelectionListAdapter.uex' path='docs/doc[@for="HtmlSelectionListAdapter.RenderAsHiddenInputField"]/*' />
        protected override void RenderAsHiddenInputField(HtmlMobileTextWriter writer)
        {
            // Optimization - if viewstate is enabled for this control, and the
            // postback returns to this page, we just let it do the trick.
            // One catch though - if the control is multiselect, it always
            // interprets return values, so we do need to write out.

            if (Control.IsMultiSelect || Control.Form.Action.Length > 0 || !IsViewStateEnabled())
            {
                String uniqueID = Control.UniqueID;
                MobileListItemCollection items = Control.Items;
                for (int i = 0; i < items.Count; i++)
                {
                    if (items[i].Selected)
                    {
                        writer.WriteHiddenField(uniqueID, i.ToString(CultureInfo.InvariantCulture));
                    }
                }
            }
        }
Exemplo n.º 6
0
        /// <include file='doc\HtmlListAdapter.uex' path='docs/doc[@for="HtmlListAdapter.RenderList"]/*' />
        protected virtual void RenderList(HtmlMobileTextWriter writer)
        {
            MobileListItemCollection items = Control.Items;
            Wrapping wrap = Style.Wrapping; // used for tables, no decoration case.

            if (items.Count == 0)
            {
                return;
            }

            int pageStart = Control.FirstVisibleItemIndex;
            int pageSize  = Control.VisibleItemCount;

            // Determine what markup to use.

            String         listSuffix, itemPrefix, itemSuffix;
            ListDecoration decoration  = Control.Decoration;
            bool           insideStyle = true;

            // We know that for table tag, outer style doesn't carry over
            // into inside tags so style state needs to be reset.
            // For other cases, we enter the style here once and exit at the
            // end once.
            if (decoration != ListDecoration.None || !Device.Tables)
            {
                writer.EnterStyle(Style);
                insideStyle = false;
            }

            switch (decoration)
            {
            case ListDecoration.Bulleted:
                writer.WriteLine("<ul>");
                listSuffix = "</ul>";
                itemPrefix = "<li>";
                itemSuffix = "</li>";

                if (!Device.RendersBreaksAfterHtmlLists)
                {
                    listSuffix += "<br>";
                }
                break;

            case ListDecoration.Numbered:
                if (pageStart == 0)
                {
                    writer.WriteLine("<ol>");
                }
                else
                {
                    writer.Write("<ol start=\"");
                    writer.Write(pageStart + 1);
                    writer.WriteLine("\">");
                }
                listSuffix = "</ol>";
                itemPrefix = "<li>";
                itemSuffix = "</li>";

                if (!Device.RendersBreaksAfterHtmlLists)
                {
                    listSuffix += "<br>";
                }
                break;

            default:
                if (Device.Tables)
                {
                    listSuffix     = "</table>";
                    Style.Wrapping = Wrapping.NotSet;
                    writer.EnterLayout(Style);
                    writer.WriteLine("<table>");
                    if (wrap == Wrapping.NoWrap)
                    {
                        itemPrefix = "<tr nowrap><td>";
                    }
                    else
                    {
                        itemPrefix = "<tr><td>";
                    }
                    itemSuffix = "</td></tr>";
                }
                else
                {
                    listSuffix = String.Empty;
                    itemPrefix = String.Empty;
                    itemSuffix = "<br>";
                }
                break;
            }

            bool hasCmdHandler = Control.HasItemCommandHandler;

            for (int i = 0; i < pageSize; i++)
            {
                MobileListItem item = items[pageStart + i];
                writer.Write(itemPrefix);

                if (insideStyle)
                {
                    writer.BeginStyleContext();
                    writer.EnterFormat(Style);
                }

                if (Control.ItemsAsLinks)
                {
                    RenderBeginLink(writer, item.Value);
                }
                else if (hasCmdHandler)
                {
                    writer.WriteBeginTag("a");
                    RenderPostBackEventAsAttribute(writer, "href", item.Index.ToString(CultureInfo.InvariantCulture));
                    writer.Write(">");
                }
                writer.WriteEncodedText(item.Text);

                if (hasCmdHandler || Control.ItemsAsLinks)
                {
                    RenderEndLink(writer);
                }

                if (insideStyle)
                {
                    writer.ExitFormat(Style);
                    writer.EndStyleContext();
                }
                writer.WriteLine(itemSuffix);
            }

            if (listSuffix == null || listSuffix.Length > 0)
            {
                writer.WriteLine(listSuffix);
            }

            if (decoration != ListDecoration.None || !Device.Tables)
            {
                writer.ExitStyle(Style);
            }
            else
            {
                writer.ExitLayout(Style);
                Style.Wrapping = wrap;
            }
        }
        /// <include file='doc\HtmlSelectionListAdapter.uex' path='docs/doc[@for="HtmlSelectionListAdapter.Render"]/*' />
        public override void Render(HtmlMobileTextWriter writer)
        {
            MobileListItemCollection items      = Control.Items;
            ListSelectType           selectType = Control.SelectType;

            if (items.Count == 0 &&
                selectType != ListSelectType.ListBox &&
                selectType != ListSelectType.MultiSelectListBox)
            {
                return;
            }

            int    selectedIndex = Control.SelectedIndex;
            String renderName;

            if (Device.RequiresAttributeColonSubstitution)
            {
                renderName = Control.UniqueID.Replace(':', ',');
            }
            else
            {
                renderName = Control.UniqueID;
            }

            switch (selectType)
            {
            case ListSelectType.DropDown:
            case ListSelectType.ListBox:
            case ListSelectType.MultiSelectListBox:

                if (items.Count == 0 && !Device.CanRenderEmptySelects)
                {
                    break;
                }

                writer.EnterLayout(Style);
                writer.WriteBeginTag("select");

                if (selectType == ListSelectType.MultiSelectListBox)
                {
                    writer.Write(" multiple");
                }

                if (selectType == ListSelectType.ListBox || selectType == ListSelectType.MultiSelectListBox)
                {
                    writer.WriteAttribute("size", Control.Rows.ToString(CultureInfo.InvariantCulture));
                }

                writer.WriteAttribute("name", renderName);
                writer.Write(">");

                for (int itemIndex = 0; itemIndex < items.Count; itemIndex++)
                {
                    MobileListItem item = items[itemIndex];
                    writer.WriteBeginTag("option");
                    WriteItemValueAttribute(writer, itemIndex, item.Value);
                    if (item.Selected && (Control.IsMultiSelect || itemIndex == selectedIndex))
                    {
                        writer.Write(" selected>");
                    }
                    else
                    {
                        writer.Write(">");
                    }
                    writer.WriteEncodedText(item.Text);
                    writer.WriteLine("");
                }
                writer.Write("</select>");

                if (Device.HidesRightAlignedMultiselectScrollbars &&
                    selectType == ListSelectType.MultiSelectListBox)
                {
                    // nested if for perf
                    if ((Alignment)Style[Style.AlignmentKey, true] == Alignment.Right)
                    {
                        writer.Write("&nbsp;&nbsp;&nbsp;&nbsp;");
                    }
                }
                writer.WriteLine("");

                if (!Page.DesignMode)
                {
                    writer.ExitLayout(Style, Control.BreakAfter);
                }
                else
                {
                    writer.ExitLayout(Style, false);
                }
                break;

            case ListSelectType.Radio:
            case ListSelectType.CheckBox:

                String selectTypeString =
                    (selectType == ListSelectType.Radio) ?
                    "radio" :
                    "checkbox";
                Alignment alignment = (Alignment)Style[Style.AlignmentKey, true];
                if (!Device.Tables || alignment == Alignment.Left || alignment == Alignment.NotSet)
                {
                    writer.EnterStyle(Style);
                    bool breakAfter = false;
                    for (int itemIndex = 0; itemIndex < items.Count; itemIndex++)
                    {
                        if (breakAfter)
                        {
                            writer.WriteBreak();
                        }
                        MobileListItem item = items[itemIndex];

                        writer.WriteBeginTag("input");
                        writer.WriteAttribute("type", selectTypeString);
                        writer.WriteAttribute("name", renderName);
                        WriteItemValueAttribute(writer, itemIndex, item.Value);
                        if (item.Selected &&
                            (Control.IsMultiSelect || itemIndex == selectedIndex) &&
                            Device.SupportsUncheck)
                        {
                            writer.Write(" checked>");
                        }
                        else
                        {
                            writer.Write(">");
                        }
                        writer.WriteEncodedText(item.Text);
                        breakAfter = true;
                    }
                    writer.ExitStyle(Style, Control.BreakAfter);
                }
                else     // Device supports tables and alignment is non default.
                {
                    Wrapping wrapping = (Wrapping)Style[Style.WrappingKey, true];
                    bool     nowrap   = (wrapping == Wrapping.NoWrap);

                    writer.EnterLayout(Style);
                    writer.WriteFullBeginTag("table");
                    writer.BeginStyleContext();
                    for (int itemIndex = 0; itemIndex < items.Count; itemIndex++)
                    {
                        MobileListItem item = items[itemIndex];
                        writer.WriteFullBeginTag("tr");
                        writer.WriteBeginTag("td");
                        if (nowrap)
                        {
                            writer.WriteAttribute("nowrap", "true");
                        }
                        writer.Write(">");

                        writer.WriteBeginTag("input");
                        writer.WriteAttribute("type", selectTypeString);
                        writer.WriteAttribute("name", renderName);
                        WriteItemValueAttribute(writer, itemIndex, item.Value);
                        if (item.Selected &&
                            (Control.IsMultiSelect || itemIndex == selectedIndex) &&
                            Device.SupportsUncheck)
                        {
                            writer.Write(" checked>");
                        }
                        else
                        {
                            writer.Write(">");
                        }

                        writer.MarkStyleContext();
                        writer.EnterFormat(Style);
                        writer.WriteEncodedText(item.Text);
                        writer.ExitFormat(Style);
                        writer.UnMarkStyleContext();
                        writer.WriteEndTag("td");
                        writer.WriteEndTag("tr");
                    }
                    writer.WriteEndTag("table");
                    writer.EndStyleContext();
                    writer.ExitFormat(Style, Control.BreakAfter);
                }
                break;
            }
        }
        /// <include file='doc\ChtmlSelectionListAdapter.uex' path='docs/doc[@for="ChtmlSelectionListAdapter.Render"]/*' />
        public override void Render(HtmlMobileTextWriter writer)
        {
            ListSelectType selectType = Control.SelectType;

            if (selectType == ListSelectType.MultiSelectListBox &&
                Device.SupportsSelectMultiple == false)
            {
                // Render occurs after SaveViewState.  Here we make a temp
                // change which is not persisted to the view state.
                Control.SelectType = selectType = ListSelectType.CheckBox;
            }

            if (!Device.RequiresUniqueHtmlCheckboxNames ||
                selectType != ListSelectType.CheckBox)
            {
                base.Render(writer);
            }
            else
            {
                MobileListItemCollection items = Control.Items;
                if (items.Count == 0)
                {
                    return;
                }
                writer.EnterStyle(Style);
                bool writeBreak = false;
                foreach (MobileListItem item in items)
                {
                    int index = items.IndexOf(item);
                    if (writeBreak)
                    {
                        writer.WriteBreak();
                    }

                    writer.Write("<input type=\"checkbox\" name=\"");
                    if (Device.RequiresAttributeColonSubstitution)
                    {
                        writer.Write(Control.UniqueID.Replace(':', ','));
                    }
                    else
                    {
                        writer.Write(Control.UniqueID);
                    }
                    writer.Write(Constants.SelectionListSpecialCharacter);
                    writer.Write(index);
                    writer.Write("\" value=\"");
                    if (!String.IsNullOrEmpty(Control.Form.Action))
                    {
                        writer.WriteEncodedText(item.Value);
                    }
                    else
                    {
                        writer.Write(item.Index.ToString(CultureInfo.InvariantCulture));
                    }
                    if (item.Selected &&
                        Device.SupportsUncheck)
                    {
                        writer.Write("\" checked>");
                    }
                    else
                    {
                        writer.Write("\">");
                    }

                    writer.WriteText(item.Text, true);
                    writeBreak = true;
                }
                writer.ExitStyle(Style, Control.BreakAfter);
            }
        }
        /// <summary>
        ///    <para>
        ///       Gets the HTML to be used for the design-time representation
        ///       of the control.
        ///    </para>
        /// </summary>
        /// <returns>
        ///    <para>
        ///       The design-time HTML.
        ///    </para>
        /// </returns>
        protected override String GetDesignTimeNormalHtml()
        {
            const int   numberOfStaticItems = 5;
            IEnumerable selectedDataSource = null;
            String      oldDataTextField = null, oldDataValueField = null;
            bool        dummyDataSource = false;

            DesignerTextWriter htmlWriter = new DesignerTextWriter(true);

            MobileListItemCollection items = _selectionList.Items;

            Debug.Assert(items != null, "Items is null in LisControl");

            if (items.Count > 0)
            {
                _selectionList.Adapter.Render(htmlWriter);
            }
            else
            {
                MobileListItem[] oldItems = items.GetAll();
                int sampleRows            = numberOfStaticItems;

                // try designtime databinding.
                selectedDataSource = GetResolvedSelectedDataSource();

                IEnumerable designTimeDataSource =
                    GetDesignTimeDataSource(
                        selectedDataSource,
                        sampleRows,
                        out dummyDataSource);

                // If dummy datasource is applied, change the data fields so that
                // dummy source will be rendered.
                if (dummyDataSource)
                {
                    oldDataTextField              = _selectionList.DataTextField;
                    oldDataValueField             = _selectionList.DataValueField;
                    _selectionList.DataTextField  = "Column0";
                    _selectionList.DataValueField = "Column1";
                }

                try
                {
                    _selectionList.DataSource = designTimeDataSource;
                    _selectionList.DataBind();
                    _selectionList.Adapter.Render(htmlWriter);
                }
                finally
                {
                    _selectionList.DataSource = null;
                    _selectionList.Items.SetAll(oldItems);

                    if (dummyDataSource)
                    {
                        _selectionList.DataTextField  = oldDataTextField;
                        _selectionList.DataValueField = oldDataValueField;
                    }
                }
            }

            return(htmlWriter.ToString());
        }
Exemplo n.º 10
0
        /// <summary>
        ///    <para>
        ///       Gets the HTML to be used for the design-time representation
        ///       of the control.
        ///    </para>
        /// </summary>
        /// <returns>
        ///    <para>
        ///       The design-time HTML.
        ///    </para>
        /// </returns>
        /// <remarks>
        ///    <para>
        ///       The rule for handing DesignTimeHTML is similar to System.Web.UI.DataList control,
        ///       if list has a HTML templateset, then generate sample data from static data or
        ///       dynamic data (if static data does not exist). Show the sample data with templates
        ///       applied.
        ///    </para>
        /// </remarks>
        protected override String GetDesignTimeNormalHtml()
        {
            IEnumerable selectedDataSource = null;
            String      oldDataTextField = null, oldDataValueField = null;
            bool        dummyDataSource = false;

            DesignerTextWriter writer = new DesignerTextWriter(true);

            // Apply the current device specific
            if (_list.DeviceSpecific != null)
            {
                _list.DeviceSpecific.SetDesignerChoice(CurrentChoice);
            }

            MobileListItemCollection items = _list.Items;

            Debug.Assert(items != null, "Items is null in LisControl");
            MobileListItem[] oldItems = items.GetAll();

            // Hack: If List is templated, use DataBind() to create child controls.
            //       If it is empty, use dummy data source to create fake child controls.
            if (_list.IsTemplated || items.Count == 0)
            {
                int sampleRows = items.Count;

                // If List does not contain any items, use five dummy items.
                if (sampleRows == 0)
                {
                    sampleRows = 5;
                }

                // try designtime databinding.
                selectedDataSource = GetResolvedSelectedDataSource();

                // Recreate the dummy data table, if number of items changed. BUG from webforms
                if (sampleRows != _numberItems)
                {
                    OnDummyDataTableChanged();

                    // keep the new item count
                    _numberItems = sampleRows;
                }

                IEnumerable designTimeDataSource =
                    GetDesignTimeDataSource(selectedDataSource, sampleRows, out dummyDataSource);

                // If dummy datasource is applied, change the data fields so that
                // dummy source will be rendered.
                if (dummyDataSource)
                {
                    oldDataTextField     = _list.DataTextField;
                    oldDataValueField    = _list.DataValueField;
                    _list.DataTextField  = "Column0";
                    _list.DataValueField = "Column1";
                }

                try
                {
                    _list.DataSource = designTimeDataSource;
                    _list.DataBind();
                    _list.Adapter.Render(writer);
                }
                finally
                {
                    _list.DataSource = null;

                    // restore the old items since databinding creates items from templates.
                    _list.Items.SetAll(oldItems);

                    // clear all child controls created by databinding.
                    _list.Controls.Clear();

                    if (dummyDataSource)
                    {
                        _list.DataTextField  = oldDataTextField;
                        _list.DataValueField = oldDataValueField;
                    }
                }
            }
            // Otherwise, list only contains static items, just render it directly.
            else
            {
                _list.Adapter.Render(writer);
            }

            return(writer.ToString());
        }
        void RenderInputElementSet(XhtmlMobileTextWriter writer)
        {
            string wrappingTag = Device.Tables ? "table" :
                                 (((string)Device["usePOverDiv"] == "true") ? "p" : "div");
            ListSelectType           selectType = Control.SelectType;
            MobileListItemCollection items      = Control.Items;
            // Review: We always render a table.  Should we optimize away the table tags when the alignment is left?
            String selectTypeString =
                (selectType == ListSelectType.Radio) ?
                "radio" :
                "checkbox";

            ClearPendingBreakIfDeviceBreaksOnBlockLevel(writer); // Since we are writing a block-level element in all cases.
            ConditionalEnterLayout(writer, Style);
            RenderOpeningListTag(writer, wrappingTag);
            for (int itemIndex = 0; itemIndex < items.Count; itemIndex++)
            {
                MobileListItem item = items[itemIndex];
                if (Device.Tables)
                {
                    writer.WriteFullBeginTag("tr");
                    writer.WriteFullBeginTag("td");
                }

                writer.WriteBeginTag("input");
                writer.WriteAttribute("type", selectTypeString);
                writer.WriteAttribute("name", Control.UniqueID);
                WriteItemValueAttribute(writer, itemIndex, item.Value);
                String accessKey = GetCustomAttributeValue(item, XhtmlConstants.AccessKeyCustomAttribute);
                if (accessKey != null && accessKey.Length > 0)
                {
                    writer.WriteAttribute("accesskey", accessKey, true);
                }
                // Assumption: Device.SupportsUncheck is always true for Xhtml devices.
                if (item.Selected &&
                    (Control.IsMultiSelect || itemIndex == Control.SelectedIndex))
                {
                    writer.Write(" checked=\"checked\"/>");
                }
                else
                {
                    writer.Write("/>");
                }

                writer.WriteEncodedText(item.Text);
                if (Device.Tables)
                {
                    writer.WriteEndTag("td");
                }
                if ((string)Device["usePOverDiv"] == "true" || !Device.Tables)
                {
                    writer.Write("<br/>");
                }
                if (Device.Tables)
                {
                    writer.WriteEndTag("tr");
                }
            }
            RenderClosingListTag(writer, wrappingTag);
            ConditionalExitLayout(writer, Style);
        }