/// <summary> /// /// </summary> private void BindDataGrid() { var list = CustomerLinkService.Where(p => p.FCode == FCode && p.FCompanyId == CurrentUser.AccountComId).ToList(); //绑定数据源 Grid1.DataSource = list; Grid1.DataBind(); }
/// <summary> /// 绑定数据表格 /// </summary> private void BindDataGrid() { int output; dynamic orderingSelector; Expression <Func <LHCustomerLink, bool> > predicate = BuildPredicate(out orderingSelector); //取数据源 IQueryable <LHCustomerLink> list = CustomerLinkService.Where(predicate, Grid1.PageSize, Grid1.PageIndex + 1, orderingSelector, EnumHelper.ParseEnumByString <OrderingOrders>(SortDirection), out output); //设置页面大小 Grid1.RecordCount = output; //绑定数据源 Grid1.DataSource = list; Grid1.DataBind(); ddlPageSize.SelectedValue = Grid1.PageSize.ToString(CultureInfo.InvariantCulture); }
private void GridEdit() { #region update var dictModified = Grid1.GetModifiedDict(); foreach (var rowKey in dictModified.Keys) { int datakey = Convert.ToInt32(Grid1.DataKeys[rowKey][1].ToString()); var sKeys = new StringBuilder(); var sValues = new StringBuilder(); foreach (var key in dictModified[rowKey].Keys) { sKeys.AppendFormat("{0},", key); } foreach (var dictValue in dictModified[rowKey].Values) { sValues.AppendFormat("{0},", dictValue); } var details = CustomerLinkService.Where(p => p.FId == datakey && p.FCompanyId == CurrentUser.AccountComId).FirstOrDefault(); var keys = sKeys.ToString().Split(','); var values = sValues.ToString().Split(','); for (int i = 0; i < keys.Count(); i++) { #region 修改内容 var key = keys[i]; var value = values[i]; if (!string.IsNullOrEmpty(key)) { if (details != null) { if (key.Equals("FLinkman")) { details.FLinkman = value; } if (key.Equals("FAddress")) { details.FAddress = value; } if (key.Equals("FPhome")) { details.FPhome = value; } if (key.Equals("FMoile")) { details.FMoile = value; } if (key.Equals("FMemo")) { details.FMemo = value; } if (key.Equals("FType")) { details.FType = value; } } } #endregion } CustomerLinkService.SaveChanges(); } #endregion var addList = Grid1.GetNewAddedList(); #region AddRow foreach (var add in addList) { var sKeys = new StringBuilder(); var sValues = new StringBuilder(); foreach (var key in add.Keys) { sKeys.AppendFormat("{0},", key); } foreach (var dictValue in add.Values) { sValues.AppendFormat("{0},", dictValue); } var keys = sKeys.ToString().Split(','); var values = sValues.ToString().Split(','); var details = new LHCustomerLink(); for (int i = 0; i < keys.Count(); i++) { #region 修改内容 details.FCompanyId = CurrentUser.AccountComId; details.FCode = FCode; var key = keys[i]; var value = values[i]; if (!string.IsNullOrEmpty(key)) { if (key.Equals("FLinkman")) { details.FLinkman = value; } if (key.Equals("FAddress")) { details.FAddress = value; } if (key.Equals("FPhome")) { details.FPhome = value; } if (key.Equals("FMoile")) { details.FMoile = value; } if (key.Equals("FMemo")) { details.FMemo = value; } if (key.Equals("FType")) { details.FType = value; } } #endregion } CustomerLinkService.Add(details); } #endregion }