Dynamic ReadOnly in DetailsView

Discussion in 'ASP .Net' started by =?Utf-8?B?TWlrZSBE?=, Oct 29, 2007.

  1. I need to dynamically set the ReadOnly value in a BoundField in a
    DetailsView. The DetailsView is generated from a GridView selection and has
    both Edit and New buttons. I need to be able to set the readonly property on
    one of the fields depending on the user's group. I have tried to access the
    property by Detailsview1.Fields[3].Readonly and by
    Detailsview1.FindControl("Dept").Readonly but neither exist. Is it even
    possible to set the readonly property of a BoundField in the code-behind?
    --
    Regards,

    Mike D
    Coding in C# since Feb 2007
     
    =?Utf-8?B?TWlrZSBE?=, Oct 29, 2007
    #1
    1. Advertising

  2. =?Utf-8?B?TWlrZSBE?=

    Angel Guest

    Yes Mike! I do that routinely... But it also depends. I do not relie on any
    declarative stuff or Datasouce cotrols so I completely bound my control
    programmatically.

    In my column definition I do the following

    ' category id
    bf = New boundField
    bf.DataField="CategoryID"
    bf.HeaderText = "Category ID"
    bf.ReadOnly = True ' This could be of course done dynamically at this point
    detailsView1.Fields.add(bf)

    I tested this before answering you and it works.

    --
    aaa


    "Mike D" wrote:

    > I need to dynamically set the ReadOnly value in a BoundField in a
    > DetailsView. The DetailsView is generated from a GridView selection and has
    > both Edit and New buttons. I need to be able to set the readonly property on
    > one of the fields depending on the user's group. I have tried to access the
    > property by Detailsview1.Fields[3].Readonly and by
    > Detailsview1.FindControl("Dept").Readonly but neither exist. Is it even
    > possible to set the readonly property of a BoundField in the code-behind?
    > --
    > Regards,
    >
    > Mike D
    > Coding in C# since Feb 2007
     
    Angel, Jan 14, 2008
    #2
    1. Advertising

  3. =?Utf-8?B?TWlrZSBE?=

    Mike D Guest

    Thanks that helped!
    --
    Regards,

    Mike D
    Coding in C# since Feb 2007


    "Angel" wrote:

    > Yes Mike! I do that routinely... But it also depends. I do not relie on any
    > declarative stuff or Datasouce cotrols so I completely bound my control
    > programmatically.
    >
    > In my column definition I do the following
    >
    > ' category id
    > bf = New boundField
    > bf.DataField="CategoryID"
    > bf.HeaderText = "Category ID"
    > bf.ReadOnly = True ' This could be of course done dynamically at this point
    > detailsView1.Fields.add(bf)
    >
    > I tested this before answering you and it works.
    >
    > --
    > aaa
    >
    >
    > "Mike D" wrote:
    >
    > > I need to dynamically set the ReadOnly value in a BoundField in a
    > > DetailsView. The DetailsView is generated from a GridView selection and has
    > > both Edit and New buttons. I need to be able to set the readonly property on
    > > one of the fields depending on the user's group. I have tried to access the
    > > property by Detailsview1.Fields[3].Readonly and by
    > > Detailsview1.FindControl("Dept").Readonly but neither exist. Is it even
    > > possible to set the readonly property of a BoundField in the code-behind?
    > > --
    > > Regards,
    > >
    > > Mike D
    > > Coding in C# since Feb 2007
     
    Mike D, Jan 15, 2008
    #3
  4. =?Utf-8?B?TWlrZSBE?=

    Geo Guest

    Why dont you try using a ItemTemplate inside a DetailsView. Then you can
    access it and make it using FIND CONTROL and make it read only. Just sharing
    an idea incase if the other method didnt work.

    "Mike D" wrote:

    > Thanks that helped!
    > --
    > Regards,
    >
    > Mike D
    > Coding in C# since Feb 2007
    >
    >
    > "Angel" wrote:
    >
    > > Yes Mike! I do that routinely... But it also depends. I do not relie on any
    > > declarative stuff or Datasouce cotrols so I completely bound my control
    > > programmatically.
    > >
    > > In my column definition I do the following
    > >
    > > ' category id
    > > bf = New boundField
    > > bf.DataField="CategoryID"
    > > bf.HeaderText = "Category ID"
    > > bf.ReadOnly = True ' This could be of course done dynamically at this point
    > > detailsView1.Fields.add(bf)
    > >
    > > I tested this before answering you and it works.
    > >
    > > --
    > > aaa
    > >
    > >
    > > "Mike D" wrote:
    > >
    > > > I need to dynamically set the ReadOnly value in a BoundField in a
    > > > DetailsView. The DetailsView is generated from a GridView selection and has
    > > > both Edit and New buttons. I need to be able to set the readonly property on
    > > > one of the fields depending on the user's group. I have tried to access the
    > > > property by Detailsview1.Fields[3].Readonly and by
    > > > Detailsview1.FindControl("Dept").Readonly but neither exist. Is it even
    > > > possible to set the readonly property of a BoundField in the code-behind?
    > > > --
    > > > Regards,
    > > >
    > > > Mike D
    > > > Coding in C# since Feb 2007
     
    Geo, Jan 28, 2008
    #4
    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. Replies:
    1
    Views:
    3,036
    Flinky Wisty Pomm
    Apr 2, 2006
  2. gerry
    Replies:
    3
    Views:
    2,100
    Walter Wang [MSFT]
    Sep 26, 2007
  3. Jonathan Hyatt
    Replies:
    1
    Views:
    2,135
    Jonathan Hyatt
    Jun 8, 2004
  4. Feege
    Replies:
    0
    Views:
    502
    Feege
    Dec 20, 2005
  5. Randell D.
    Replies:
    5
    Views:
    157
Loading...

Share This Page