Hi,
I think I have quite a specific task. I have a page, where I need to generate multiple grids, for different types of entities.
And the thing is that on grid generation step I do not know types of entities that I will have, in other words I have a set of 'Type' entities each describing some class, so I can not declare grids in 'aspx' page, but I need to generate them in code behind.
I am trying to generate grid in the code behind using this code:
var grid = new RadGrid();
grid.AutoGenerateColumns = true;
grid.MasterTableView.EditMode = GridEditMode.InPlace;
grid.DataSource = input.GetDataForEngineQueryPosition(job, metricKey); //just collection of entities
grid.Visible = true;
grid.DataBind();
Quite simple, and the code is working, I do see the grid with appropriate columns, but I cant edit the values in the cells.
I also tried to generate columns manually depending on properties provided by 'type' entity, like this:
var grid = new RadGrid();
grid.AutoGenerateColumns = false;
var propertiesBindingFlags = System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance;
var customizableFields = input.CustomizableProperties;
bool showAll = false;
foreach(var property in inputType.GetProperties(propertiesBindingFlags))
{
var field = new Telerik.Web.UI.GridBoundColumn();
field.DataField = property.Name;
field.HeaderText = property.Name;
field.ReadOnly = false;
field.Visible = true;
grid.Columns.Add(field);
}
grid.MasterTableView.EditMode = GridEditMode.InPlace;
grid.DataSource = input.GetDataForEngineQueryPosition(job, metricKey);
grid.Visible = true;
grid.DataBind();
Values are displayed correctly in this case, but unlike for the autogeneration I don't see proper controls for every column (like checkbox) and I understand why.
But I still can't edit the values in the cells.
Also, after updating the values I need to submit them back to the server, what is the best way to do this.
Thanks.
Kind regards,
Erik Martirosyan