コード例 #1
0
        protected virtual void CreateControlHierarchy(bool useDataSource)
        {
            IEnumerable dataSource = null;
            int         itemCount  = 0;

            _items = null;

            ArrayList dataKeysArray = DataKeysArray;
            string    dataKeyField  = null;

            if (useDataSource)
            {
                dataSource = GetDataSource();

                dataKeysArray.Clear();
                dataKeyField = DataKeyField;
            }
            else
            {
                dataSource = new object[(int)ViewState["Items"]];
            }

            if (dataSource != null)
            {
                Table outerTable = new Table();
                Controls.Add(outerTable);

                ListViewItem headerItem = null;
                ListViewItem footerItem = null;

                if (_headerTemplate != null)
                {
                    TableRow headerRow = new TableRow();
                    outerTable.Rows.Add(headerRow);
                    headerItem = CreateListViewItem(headerRow, -1, ListViewItemType.Header, null, useDataSource);
                }

                TableRow bodyRow = new TableRow();
                outerTable.Rows.Add(bodyRow);

                TableCell bodyCell = new TableCell();
                bodyRow.Cells.Add(bodyCell);

                ListViewPanel viewPanel = new ListViewPanel();
                bodyCell.Controls.Add(viewPanel);

                ListViewTable innerTable = CreateListViewTable();
                viewPanel.Controls.Add(innerTable);

                TableRow itemsRow = new TableRow();
                innerTable.Rows.Add(itemsRow);

                int editIndex     = EditIndex;
                int selectedIndex = SelectedIndex;

                int itemIndex = 0;
                foreach (object dataItem in dataSource)
                {
                    ListViewItemType itemType = ListViewItemType.Item;

                    if (itemIndex == editIndex)
                    {
                        itemType |= ListViewItemType.EditItem;
                    }
                    if (itemIndex == selectedIndex)
                    {
                        itemType |= ListViewItemType.SelectedItem;
                    }

                    CreateListViewItem(itemsRow, itemIndex, itemType, dataItem, useDataSource);
                    itemIndex++;
                    itemCount++;

                    if (useDataSource && (dataKeyField.Length != 0))
                    {
                        dataKeysArray.Add(DataBinder.GetPropertyValue(dataItem, dataKeyField));
                    }
                }

                if (_footerTemplate != null)
                {
                    TableRow footerRow = new TableRow();
                    outerTable.Rows.Add(footerRow);
                    CreateListViewItem(footerRow, -1, ListViewItemType.Footer, null, useDataSource);
                }

                _items = CreateListViewItemCollection(itemsRow.Cells, headerItem, footerItem);
            }

            if (useDataSource)
            {
                ViewState["Items"] = itemCount;
            }
        }
コード例 #2
0
ファイル: ListView.cs プロジェクト: bnantz/NCS-V1-1
        protected virtual void CreateControlHierarchy(bool useDataSource)
        {
            IEnumerable dataSource = null;
            int itemCount = 0;

            _items = null;

            ArrayList dataKeysArray = DataKeysArray;
            string dataKeyField = null;

            if (useDataSource) {
                dataSource = GetDataSource();

                dataKeysArray.Clear();
                dataKeyField = DataKeyField;
            }
            else {
                dataSource = new object[(int)ViewState["Items"]];
            }

            if (dataSource != null) {
                Table outerTable = new Table();
                Controls.Add(outerTable);

                ListViewItem headerItem = null;
                ListViewItem footerItem = null;

                if (_headerTemplate != null) {
                    TableRow headerRow = new TableRow();
                    outerTable.Rows.Add(headerRow);
                    headerItem = CreateListViewItem(headerRow, -1, ListViewItemType.Header, null, useDataSource);
                }

                TableRow bodyRow = new TableRow();
                outerTable.Rows.Add(bodyRow);

                TableCell bodyCell = new TableCell();
                bodyRow.Cells.Add(bodyCell);

                ListViewPanel viewPanel = new ListViewPanel();
                bodyCell.Controls.Add(viewPanel);

                ListViewTable innerTable = CreateListViewTable();
                viewPanel.Controls.Add(innerTable);

                TableRow itemsRow = new TableRow();
                innerTable.Rows.Add(itemsRow);

                int editIndex = EditIndex;
                int selectedIndex = SelectedIndex;

                int itemIndex = 0;
                foreach (object dataItem in dataSource) {
                    ListViewItemType itemType = ListViewItemType.Item;

                    if (itemIndex == editIndex) {
                        itemType |= ListViewItemType.EditItem;
                    }
                    if (itemIndex == selectedIndex) {
                        itemType |= ListViewItemType.SelectedItem;
                    }

                    CreateListViewItem(itemsRow, itemIndex, itemType, dataItem, useDataSource);
                    itemIndex++;
                    itemCount++;

                    if (useDataSource && (dataKeyField.Length != 0)) {
                        dataKeysArray.Add(DataBinder.GetPropertyValue(dataItem, dataKeyField));
                    }
                }

                if (_footerTemplate != null) {
                    TableRow footerRow = new TableRow();
                    outerTable.Rows.Add(footerRow);
                    CreateListViewItem(footerRow, -1, ListViewItemType.Footer, null, useDataSource);
                }

                _items = CreateListViewItemCollection(itemsRow.Cells, headerItem, footerItem);
            }

            if (useDataSource) {
                 ViewState["Items"] = itemCount;
            }
        }
コード例 #3
0
        protected virtual void PrepareControlHierarchyForRendering()
        {
            ControlCollection controls = Controls;

            if (controls.Count != 1)
            {
                return;
            }

            Table outerTable = (Table)controls[0];

            outerTable.CopyBaseAttributes(this);
            if (ControlStyleCreated)
            {
                outerTable.ApplyStyle(ControlStyle);
            }
            else
            {
                // Because we didn't create a ControlStyle yet, the settings
                // for the default style of the control need to be applied
                // to the child table control directly.
                outerTable.CellSpacing = 0;
            }

            TableRowCollection rows     = outerTable.Rows;
            TableCell          bodyCell = null;

            if (_headerTemplate != null)
            {
                TableRow headerRow = rows[0];
                if (ShowHeader)
                {
                    if (_headerStyle != null)
                    {
                        headerRow.Cells[0].MergeStyle(_headerStyle);
                    }
                }
                else
                {
                    headerRow.Visible = false;
                }

                bodyCell = rows[1].Cells[0];
            }
            if (_footerTemplate != null)
            {
                TableRow footerRow = rows[rows.Count - 1];
                if (ShowFooter)
                {
                    if (_footerStyle != null)
                    {
                        footerRow.Cells[0].MergeStyle(_footerStyle);
                    }
                }
                else
                {
                    footerRow.Visible = false;
                }
            }

            if (bodyCell == null)
            {
                bodyCell = rows[0].Cells[0];
            }

            ListViewPanel viewPanel = (ListViewPanel)bodyCell.Controls[0];

            if (_viewStyle != null)
            {
                viewPanel.ApplyStyle(_viewStyle);

                if (ShowScrollBars)
                {
                    viewPanel.Style["overflow"]   = "scroll";
                    viewPanel.Style["overflow-x"] = "auto";
                    viewPanel.Style["overflow-y"] = "auto";
                }
            }

            ListViewTable bodyTable = (ListViewTable)viewPanel.Controls[0];

            bodyTable.Columns = Columns;

            foreach (ListViewItem item in _items)
            {
                TableItemStyle   style          = _itemStyle;
                TableItemStyle   compositeStyle = null;
                ListViewItemType itemType       = item.ItemType;

                if (((itemType & ListViewItemType.EditItem) != 0) && (_editItemStyle != null))
                {
                    if (style != null)
                    {
                        compositeStyle = new TableItemStyle();
                        compositeStyle.CopyFrom(style);
                        compositeStyle.CopyFrom(_editItemStyle);
                    }
                    else
                    {
                        style = _editItemStyle;
                    }
                }
                if (((itemType & ListViewItemType.SelectedItem) != 0) && (_selectedItemStyle != null))
                {
                    if (compositeStyle != null)
                    {
                        compositeStyle.CopyFrom(_selectedItemStyle);
                    }
                    else if (style != null)
                    {
                        compositeStyle = new TableItemStyle();
                        compositeStyle.CopyFrom(style);
                        compositeStyle.CopyFrom(_selectedItemStyle);
                    }
                    else
                    {
                        style = _selectedItemStyle;
                    }
                }

                if (compositeStyle != null)
                {
                    item.MergeStyle(compositeStyle);
                }
                else if (style != null)
                {
                    item.MergeStyle(style);
                }

                if (_renderClickSelectScript)
                {
                    if ((itemType & ListViewItemType.SelectedItem) == 0)
                    {
                        item.Attributes["onclick"] = Page.GetPostBackEventReference(this, "S" + item.ItemIndex);
                        item.Style["cursor"]       = "hand";
                    }
                }
            }
        }