Hi ,
I am creating a column Image Button dynamical but when i click on image ItemCommand is not get Fired .
Below are the code
void GridUserControl_OnInitializeRow(RowEventArgs e){var objCustomItemTemplateEdit = new EditCustomItemTemplate();objCustomItemTemplateEdit.ID = "Edit_" + selectedSpecialty;e.Row.Items[3].Template = objCustomItemTemplateEdit;
var objCustomItemTemplateDelete = new DeleteCustomItemTemplate();objCustomItemTemplateDelete.ID = "Delete_" + selectedSpecialty;e.Row.Items[4].Template = objCustomItemTemplateDelete;}
public class EditCustomItemTemplate : ITemplate{public string ID { get; set; }public string CommandArg { get; set; }
public void InstantiateIn(Control container){ImageButton p = new ImageButton();p.ID = ID;p.EnableViewState = true;p.CommandArgument = CommandArg;p.CommandName = "Edit";p.ViewStateMode = ViewStateMode.Enabled;p.ImageUrl = "Edit.png";container.Controls.Add(p);}
}
public class DeleteCustomItemTemplate : ITemplate{public string ID { get; set; }public string CommandArg { get; set; }
public void InstantiateIn(Control container){ImageButton p = new ImageButton();p.ID = ID;p.EnableViewState = true;p.CommandArgument = CommandArg;p.CommandName = "Delete";p.ViewStateMode = ViewStateMode.Enabled;p.ImageUrl = "dele.png"p.OnClientClick = "return confirm('Are you sure you want to delete this record?');";container.Controls.Add(p);}}
The reason that the ItemCommand event is failing to fire is that templates of the grid are instantiated in the DataBind method of the grid. Normally if this method is not manually called it gets called during the OnPreRender event for the grid. However, when using this with the ItemCommand the DataBind event is fired after the ItemCommand event is supposed to fire. Since the templates haven't been instantiated in time the event can't find the templates and fails out silently.
The way to resolve this issue is to ensure that the templates exist. You can do this by adding the following code to your PageLoad event:
if (IsPostBack) {
WebDataGrid1.EnsureTemplates();}
I tried using EnsureTemplates() method but it is not working.
You can find code below mention link
http://www.infragistics.com/community/forums/p/109368/514634.aspx#514634
Thanks,
Santosh.
Hello Santosh,
I have applied EnsureTemplates() and the event is fired. Have a look at the attached sample.
Code snippet:
protected void Page_Load(object sender, EventArgs e){ if (!IsPostBack) { if (!string.IsNullOrEmpty(formID)) { ParseXML(); } } if (newList != null) { WebDataGrid1.DataSource = newList; WebDataGrid1.DataBind(); } else if (dtblDataSource != null) { WebDataGrid1.DataSource = dtblDataSource; WebDataGrid1.DataBind(); }
WebDataGrid1.EnsureTemplates(); }}
Attach file is corrupt can you please attach the new file
Try this google drive link:
https://drive.google.com/file/d/0B1pRPnoDJMTTSXo4ZkFsSTJTaEk/view?usp=sharing
Its working first time but again when i click on dynamic generated image button its not get fired .... :(
Santosh
This is strange, in the sample that I've sent you ItemCommand server event is fired again while constantly clicking the button.