Hello,
I've a WebDataGrid inside a WebDialogWindow as follows (no matter with or without the behaviours):
<ig:WebDataGrid ID="DlgFirezonesWDG" runat="server"> <Behaviors> <ig:ColumnMoving></ig:ColumnMoving> <ig:ColumnResizing></ig:ColumnResizing> <ig:Filtering></ig:Filtering> <ig:Sorting></ig:Sorting> <ig:SummaryRow></ig:SummaryRow> </Behaviors></ig:WebDataGrid>
code behind:
List<area>f=area.GetList(); //some fields: int id, string name, string number, subarea, ... //where subarea is of type areaAreasWDG.DataSource=f;AreasWDG.DataKeyFields="id";AreasWDG.DataBind();AreasWDG.Columns[0].Hidden=true;
All other grid properties have default values.
Everything works fine as long as I do not try to hide a column which is what I really want to, since e. g. the subarea field is an entity object and does not need to show up.
If I try to hide a column, no matter using the index (0, 1 or whatever) or the key ("id", "subarea", ...) I get a NullReferenceException. This is because AreasWDG.Columns actually does not contain any columns. Nevertheless AreasWDG.Rows does (count=6) and AreasWDG.HasColumns is true.
Am I doing something wrong or why does this happen?
regards
Hi bernhardus,
You are actually doing something wrong. HasColumns returns true if the internal columns collection has been defined, which happens when .Columns is accessed. The problem however is that you are autogenerating your columns. The columns collection contains only columns you have defined. Autogenerated ones are available only internally. This is how the grid has always worked. If you want to work with the columns on the server, you should turn of AutoGenerateColumns and then create the columns from your data source. Another solution I've seen on the forums is to access the internal column off of the Column property of GridRecordItem (the cell) of a row.
regards,David Young
Hi,
thank you for your answer and sorry for the delay.
In fact I did not know that, and everything I saw about column hiding was using the .Columns property.
So thanks again
Bernhardus