Hi ,
I am creating a column Image Button dynamical but when i click on image entire page is post back and my dynamically created column are disappeared (not persist).
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); } }
Hello Santosh,
Thank you for the code provided. It is working as expected - I have tried it in a sample of mine. Clicking on the templates does not cause any issues in the app. Please provide more context on how you create the dynamical columns, so that I can try to replicate this in my sample and investigate.
We have one User Control and it that User control we have WebDataGrid. Same User Control are used in every Client view page.
We are defining column in xml file from that it picking up column name which has to be shown in the screen. Same xml file is read at every time when data (DataTable or List) is assigned to a grid data source.
I had on method BindDataToGrid() , If i called mention method at every post back then after clicking on image button not disappear but unnecessary database is hit.
With this on my dynamically generated column when i clicked "ItemCommand" event is not get fired.
Can you please share your sample code ...