コード例 #1
0
        public void FormViewCreate_InsertItem()
        {
            var item = new Category();

            TryUpdateModel(item);
            if (ModelState.IsValid)
            {
                _context.Categories.Add(item);
                _context.SaveChanges();
            }

            FormView FormViewCreate = UpdatePanelCreate.FindControl("FormViewCreate") as FormView;

            FormViewCreate.Visible = false;

            ListView  ListViewCategories  = UpdatePanelCategories.FindControl("ListViewCategories") as ListView;
            DataPager DataPagerCategories = ListViewCategories.FindControl("DataPagerCategories") as DataPager;

            int lastpage = (DataPagerCategories.TotalRowCount + 1) / DataPagerCategories.PageSize;

            if (((DataPagerCategories.TotalRowCount + 1) % DataPagerCategories.PageSize) == 0)
            {
                lastpage--;
            }

            DataPagerCategories.SetPageProperties(lastpage * DataPagerCategories.PageSize, DataPagerCategories.MaximumRows, true);
        }
コード例 #2
0
        // The id parameter name should match the DataKeyNames value set on the control
        public void ListViewCategories_DeleteItem(int Id)
        {
            Category item = null;

            item = _context.Categories.Find(Id);
            if (item == null)
            {
                // The item wasn't found
                ModelState.AddModelError("", String.Format("Item with id {0} was not found", Id));
                return;
            }

            _context.Categories.Remove(item);
            _context.SaveChanges();

            ListView  ListViewCategories  = UpdatePanelCategories.FindControl("ListViewCategories") as ListView;
            DataPager DataPagerCategories = ListViewCategories.FindControl("DataPagerCategories") as DataPager;

            int lastpage = (DataPagerCategories.TotalRowCount - 1) / DataPagerCategories.PageSize;

            if (((DataPagerCategories.TotalRowCount - 1) % DataPagerCategories.PageSize) == 0)
            {
                lastpage--;
            }
            DataPagerCategories.SetPageProperties((lastpage) * DataPagerCategories.PageSize, DataPagerCategories.MaximumRows, true);
        }