how to make programmatically a field of detailsview read-only ?

C

Cas

Hi,

I defined a detailsview in insertmode in the .aspx file.
In the code-behind, i created 6 fields and adding them to the detailsview.
Independantly of the detailsview, I use the datareader to read data from a
database.
Now, when the second field of the datareader (dtreader.GetString(1))
contains an "x", the field created and added to the detailsview must be
read-only.
I tried in the code below, but i can still input data into that field.
Everything works except the read-only property.

Thanks for hrlp
Cas


My code:
In aspx file:
----------
.....
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="....></asp:SqlDataSource>
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
CellPadding="3" DataSourceID="SqlDataSource1" DefaultMode="Insert">
</asp:DetailsView>
......

In code-behind file:
------------------
......
For i = 0 to 5
dtreader.Read() 'connected to database
bf(i) = New BoundField
bf(i).DataField = "fld" & i + 1
DetailsView1.Fields.Add(bf(i))
If dtreader.GetString(1) = "x" Then
DetailsView1.Fields(i).HeaderText = dtreader.GetString(2)
DetailsView1.Fields(i).HeaderStyle.Font.Underline = True
bf(i).ReadOnly = True
' this doesn't work
'DetailsView1.Fields(i).readonly
'doesn't exist
End If
next
......
 

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

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,052
Latest member
LucyCarper

Latest Threads

Top