Reputation: 2499
How to make ASP.NET DataGrid column Read-only in run-time using code behind?
I know this can be done in ASPX:
<ASP:BoundColumn HeaderText="MHN" ReadOnly="True" SortExpression="MHNNum" DataField="MHNNum" ItemStyle-Wrap="false"
But I want to do this using code behind Vb or C#. Strangely I don't see Readonly property being exposed to DataGridColumn.
The following does not work:
Dim col as DataGridColumn=DGDrid.Columns(0)
Col.readonly=true
Upvotes: 0
Views: 2129
Reputation: 1053
Try,
((BoundColumn)DGDrid.Columns[0]).ReadOnly = true;
For the Vb:
CType(grdWaiver.Columns(0), BoundColumn).ReadOnly = True
Upvotes: 1