Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. OnRowCreated - Setting the properties of a column control

OnRowCreated - Setting the properties of a column control

Scheduled Pinned Locked Moved ASP.NET
helptutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    PeteConc
    wrote on last edited by
    #1

    Hi. I have a GridView bound to a DataTable. The columns of the GridView are TemplateColumns with a TextBox in it. The textbox columns appear with the values of the DataTable. What I am trying to do is setting the TextBox to ReadOnly if certain conditions are met. I tried to do this within a handle to OnRowCreated (I get the created row in the eventargs e.Row). The problem is that I don't know how to get the TextBox object of a specific column in that row and set it's properties to ReadOnly. Any help? Thanks!

    M 1 Reply Last reply
    0
    • P PeteConc

      Hi. I have a GridView bound to a DataTable. The columns of the GridView are TemplateColumns with a TextBox in it. The textbox columns appear with the values of the DataTable. What I am trying to do is setting the TextBox to ReadOnly if certain conditions are met. I tried to do this within a handle to OnRowCreated (I get the created row in the eventargs e.Row). The problem is that I don't know how to get the TextBox object of a specific column in that row and set it's properties to ReadOnly. Any help? Thanks!

      M Offline
      M Offline
      minhpc_bk
      wrote on last edited by
      #2

      To get reference to the TextBox, you simply use the FindControl method in the event handler of the RowCreated event:

      TextBox textBox = e.Row.FindControl('TextBoxId') as TextBox;

      You now can set the ReadOnly property of the TextBox. However, you'd better use the RowDataBound event to set the ReadOnly property as the RowCreated event always happens, and you might not need that on postback. In addition, you can also use the databinding expression to set the ReadOnly property of the TextBox in the control declaration:

      ... ReadOnly='<%# ... %>' ...

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups