Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
255
ItemCommand is not Fired when i click on Dynamically Created Image Button
posted

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);
}
}

Parents Reply Children