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

Discussion in 'ASP .Net' started by Cas, Oct 21, 2006.

  1. Cas

    Cas Guest

    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
    ......
     
    Cas, Oct 21, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. K B
    Replies:
    0
    Views:
    550
  2. keithb
    Replies:
    2
    Views:
    8,036
    keithb
    Jun 7, 2006
  3. Cas
    Replies:
    0
    Views:
    982
  4. Cas
    Replies:
    0
    Views:
    151
  5. datactrl
    Replies:
    4
    Views:
    175
    datactrl
    May 20, 2004
Loading...

Share This Page