I have a page which contains a batch mode grid (created declaratively in the aspx file) and all of the code to support the grid. This grid page is contained within an IFrame in various pages on the site. Depending upon which page is hosting the IFrame, we want to override the behavior of the grid so that the columns are read-only. The default behavior allows the columns to be edited, but when the grid is included within certain pages, we want all of the columns to be read-only.
Using (column as GridBoundColumn).ReadOnly = true; during the server-side PreRender event can fail if the column type is GridTemplateColumn (with Object reference not set). That said, I know I can respond to the BatchEditOpening event and use args.set_cancel(true) to prevent users from editing cells, but was hoping for a simple server-side solution to change the column to read-only.
For the moment, I am responding to the PreRender event and testing for ColumnType before setting the column to read-only. That just happens to work for me since the only GridTemplateColumn column is declaratively set to ReadOnly and all of the other column types seem to work. However, that seems error prone. Is there a way to easily set every column to read-only in my c# code?
Thanks.