private GridViewTextColumn GenerateTextColumn(Column column) { var bindingService = Context.Configuration.ServiceProvider.GetRequiredService <BindingCompilationService>(); //gets element with ID attribute set to GridView var gridView = (GridView)Context.View.FindControlByClientId("GridView"); //get DataContext from other column to ensure that the new column will have the same dataContext //we could also use DataContextStack.Create(typeof(GridViewData)); if we cannot copy DataContext var dataContextStack = gridView.Columns[0].GetDataContextType(); // ((GridViewData)objects[0]).AdditionalProp translates into _parent0.AdditionalProp which is equal to _this.AdditionalProp Expression <Func <object[], int> > expression = objects => ((GridViewData)objects[0]).DefaultProp; //this is quite expensive call //but soon there should be available cached version //usage will be bindingService.Cache.CreateCachedBinding("ID", new [] { dataContext }, () => CreateBinding<T>(service, o => (T)o[0], dataContext).CreateBinding(bindingService,expression,dataContextStack)); //see https://github.com/riganti/dotvvm/pull/672 for more info var valueBindingExpression = ValueBindingExpression.CreateBinding(bindingService, expression, dataContextStack); var gridViewTextColumn = new GridViewTextColumn() { HeaderText = column.Name, ValueBinding = valueBindingExpression }; return(gridViewTextColumn); }
protected override GridViewColumn CreateColumnCore(GridView gridView, PropertyDisplayMetadata property, DynamicDataContext context) { var column = new GridViewTextColumn(); column.ValueType = TextBoxHelper.GetValueTypeOrDefault(property.PropertyInfo); column.FormatString = property.FormatString; column.SetBinding(GridViewTextColumn.ValueBindingProperty, context.CreateValueBinding(property.PropertyInfo.Name)); column.IsEditable = property.IsEditAllowed; return(column); }