DataGrid: set ReadOnly property at runtime?

J

John Smith

Is it possible to set DataGrid's ReadOnly property to True/False at runtime?
An example:

<asp:datagrid id="dg1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="id" ReadOnly="True"
HeaderText="ID"></asp:BoundColumn>
</Columns>
<asp:datagrid>
 
J

John Smith

Is it possible to set DataGrid's ReadOnly property to True/False at
runtime?

P.S. My question was not limited to <asp:BoundColumn/>, but to
<asp:TemplateColumn/> as well:

<asp:datagrid id="dg1" runat="server" AutoGenerateColumns="False">
<Columns>
<ItemTemplate>
<asp:Label id="lblSum" runat="server" Text='<%#
Container.DataItem("Sum") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtSum" runat="server" Text='<%#
Container.DataItem("Sum") %>'>
</asp:TextBox>
</EditItemTemplate>
</Columns>
</asp:datagrid>

I would like to acomplish next: to show TextBoxes, only in some cells
(columns), not in all.
 
B

Bob Barrows [MVP]

John said:
Is it possible to set DataGrid's ReadOnly property to True/False at
runtime? An example:

<asp:datagrid id="dg1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="id" ReadOnly="True"
HeaderText="ID"></asp:BoundColumn>
</Columns>
<asp:datagrid>

Hmm. You asked about the grid's ReadOnly property, but you illustrated
it by showing a column's ReadOnly attribute. Which one did you really
mean?

Sub SetGridEditMode(RO as boolean)
dg1.ReadOnly = RO
End Sub

or

Sub SetGridColEditMode(colidx as int32,RO as boolean)
dim col as datagridcolumn = dg1.Columns(colidx)
End Sub
 
J

John Smith

Hmm. You asked about the grid's ReadOnly property, but you illustrated
it by showing a column's ReadOnly attribute. Which one did you really
mean?

Column's ReadOnly attribute.
Sub SetGridColEditMode(colidx as int32,RO as boolean)
dim col as datagridcolumn = dg1.Columns(colidx)
End Sub

Column doesn't have ReadOnly attribute/property?
 
B

Bob Barrows [MVP]

B

Bob Barrows [MVP]

John said:
Column's ReadOnly attribute.


Column doesn't have ReadOnly attribute/property?

You're right. I also missed a step:

dim col as boundcolumn = ctype(dg1.Columns(colidx), _
boundcolumn)
col.readonly = RO
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top