S Nash
S Nash

Reputation: 2499

How to make DataGrid column ReadOnly in runtime using code behind

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

Answers (1)

Gloria
Gloria

Reputation: 1053

Try,

 ((BoundColumn)DGDrid.Columns[0]).ReadOnly = true;

For the Vb:

 CType(grdWaiver.Columns(0), BoundColumn).ReadOnly = True

Upvotes: 1

Related Questions