e.item.FindControl of columntemplate not working...
-
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. -
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.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
-
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
thanks man, i assign the colname to the ID and it worked... Avi.
-
thanks man, i assign the colname to the ID and it worked... Avi.
fine!!;):rose: Loving Code, R. Senthil Kumaran