public void DataBind() { if (AutoGenerateColumns == true) { var builder = new GridBuilder(this); builder.Populate(this.DataSource); } else { foreach (Object o in this.DataSource) { var gridRow = new GridRow(); foreach (GridColumn col in this.Columns) { if (o != null) { var propertyInfo = o.GetType().GetProperty(col.PropertyName); Object propertyValue = propertyInfo.GetValue(o, null); String cellText; if (propertyValue == null) { cellText = ""; } else { cellText = propertyValue.ToString(); } gridRow.Cells.Add(new GridCell(cellText)); } } this.Rows.Add(gridRow); } } }
public ActionResult Index(IndexViewModel viewModel) { FillDropDowns(viewModel); var expression = viewModel.Filter.GetExpression(); var gridBuilder = new GridBuilder(viewModel.AllPosts); var posts = postRepository.Where(expression).ToList(); gridBuilder.Populate(posts); return View(viewModel); }
public void Paging() { var dataSource = this.WebLogs.GetPage(1, 1); var grid = new Grid(); var gridBuilder = new GridBuilder(grid); gridBuilder.Populate(dataSource); Assert.AreEqual(3, grid.Columns.Count); Assert.AreEqual(1, grid.Rows.Count); Assert.AreEqual(DateTime.Today.ToString(), grid.Rows[0].Cells[2].Text); Assert.AreEqual("Blog 2", grid.Rows[0].Cells[1].Text); }
public void Show_Items_In_Grid() { var dataSource = this.WebLogs.ToList(); var grid = new Grid(); var gridBuilder = new GridBuilder(grid); gridBuilder.Populate(dataSource); Assert.AreEqual(3, grid.Columns.Count); Assert.AreEqual(2, grid.Rows.Count); Assert.AreEqual(DateTime.Today.ToString(), grid.Rows[0].Cells[2].Text); Assert.AreEqual("Blog 2", grid.Rows[1].Cells[1].Text); }
public ActionResult Index(ListViewModel viewModel) { // obj var webLogGridBuilder = new GridBuilder(viewModel.DefaultGrid); // parameters -> data source var webLogDataSource = webLogGridBuilder.GetDataSourceByParameters(WebLogs).ToList(); // data source -> grid webLogGridBuilder.Populate(webLogDataSource); // obj var postGridBuilder = new GridBuilder(viewModel.Wrapper.OutroGrid); // parameters -> data source var postDataSource = postGridBuilder.GetDataSourceByParameters(from w in WebLogs.Query() from p in w.Posts select p).ToList(); // data source -> grid postGridBuilder.Populate(postDataSource); return View(viewModel); }