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. e.item.FindControl of columntemplate not working...

e.item.FindControl of columntemplate not working...

Scheduled Pinned Locked Moved ASP.NET
graphicsdesigndockerquestion
4 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.
  • J Offline
    J Offline
    JabraJabra
    wrote on last edited by
    #1

    there's big mistake for me :( i tried now to make templateColumn dynamically, everything was good and the databinding is work well but the FindControl suddenly stopped to work :( what i did is this: this is my columnTemplate implementation using System; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Drawing; using System.IO; public class EditItemTemplate : ITemplate { string columnName; public EditItemTemplate(string colname) { columnName = colname; } virtual public void InstantiateIn(System.Web.UI.Control container) { TextBox tb = new TextBox(); SetProperties(ref tb); tb.Text = ""; tb.DataBinding += new EventHandler(DataBinding); tb.Attributes.Add("ID","Name"); // IMPORTANT - set att' name container.Controls.Add(tb); } private void DataBinding(object sender, System.EventArgs e) { TextBox lc; lc = (TextBox) sender; DataGridItem container = (DataGridItem) lc.NamingContainer; lc.Text += DataBinder.Eval(container.DataItem, columnName); } } and this is my aspx.cs implementation: TemplateColumn tc = new TemplateColumn(); tc = new TemplateColumn(); tc.EditItemTemplate = new EditItemTemplate("Name"); dataGrid1.Columns.Add(tc); dataGrid1.DataBind(); but when i do this: TextBox text = (TextBox)e.Item.FindControl("Name"); it doesn't work and i get NULL... what's wrong?! Avi.

    R 1 Reply Last reply
    0
    • J JabraJabra

      there's big mistake for me :( i tried now to make templateColumn dynamically, everything was good and the databinding is work well but the FindControl suddenly stopped to work :( what i did is this: this is my columnTemplate implementation using System; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Drawing; using System.IO; public class EditItemTemplate : ITemplate { string columnName; public EditItemTemplate(string colname) { columnName = colname; } virtual public void InstantiateIn(System.Web.UI.Control container) { TextBox tb = new TextBox(); SetProperties(ref tb); tb.Text = ""; tb.DataBinding += new EventHandler(DataBinding); tb.Attributes.Add("ID","Name"); // IMPORTANT - set att' name container.Controls.Add(tb); } private void DataBinding(object sender, System.EventArgs e) { TextBox lc; lc = (TextBox) sender; DataGridItem container = (DataGridItem) lc.NamingContainer; lc.Text += DataBinder.Eval(container.DataItem, columnName); } } and this is my aspx.cs implementation: TemplateColumn tc = new TemplateColumn(); tc = new TemplateColumn(); tc.EditItemTemplate = new EditItemTemplate("Name"); dataGrid1.Columns.Add(tc); dataGrid1.DataBind(); but when i do this: TextBox text = (TextBox)e.Item.FindControl("Name"); it doesn't work and i get NULL... what's wrong?! Avi.

      R Offline
      R Offline
      R Senthil Kumaran
      wrote on last edited by
      #2

      see u r getting the name from constructor but not assigning to the textbox lc hence its giving error assign the colname to the id of the textbox lc this will work!! Loving Code, R. Senthil Kumaran

      J 1 Reply Last reply
      0
      • R R Senthil Kumaran

        see u r getting the name from constructor but not assigning to the textbox lc hence its giving error assign the colname to the id of the textbox lc this will work!! Loving Code, R. Senthil Kumaran

        J Offline
        J Offline
        JabraJabra
        wrote on last edited by
        #3

        thanks man, i assign the colname to the ID and it worked... Avi.

        R 1 Reply Last reply
        0
        • J JabraJabra

          thanks man, i assign the colname to the ID and it worked... Avi.

          R Offline
          R Offline
          R Senthil Kumaran
          wrote on last edited by
          #4

          fine!!;):rose: Loving Code, R. Senthil Kumaran

          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