예제 #1
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;
            }
        }
예제 #2
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;
            }
        }