Hi , how can i add a button inside webdatagrid column from code behind ?
Hello,
Thank you for contacting us!
Adding a button column through the code is described in this help topic - https://www.infragistics.com/help/aspnet/webdatagrid-using-item-template
I also made a sample based on your requirement.Wbdg_add_button_on_column.zip
Please, take a look at the topic and the sample and let me know if you have any questions.
Regards,
Hristo Popov
hi , thank you but this not what iam looking for its more like adding a button inside a data row like this :
in the first column along side with the data i need to display a button from code behind with every data load !
Hi,
To add a button alongside a data item in a cell, you can add this code snippet in the CustomTemplate class:
Label label = new Label(); label.ID = "TemplateLabel"; label.CssClass = "id-label"; label.Text = ((DataRowView)((TemplateContainer)container).DataItem)["id"].ToString(); container.Controls.Add(label);
Your InstantiateIn method in the CustomTemplate should look like this:
public void InstantiateIn(Control container) { Label label = new Label(); label.ID = "TemplateLabel"; label.CssClass = "id-label"; label.Text = ((DataRowView)((TemplateContainer)container).DataItem)["id"].ToString(); container.Controls.Add(label); Button delete = new Button(); delete.ID = "TemplateButton"; delete.Text = "Delete"; delete.OnClientClick = "return deleteRow()"; container.Controls.Add(delete); }
This way you are filling the container with a label that contains the respective id of the cell.
Here is a help topic for your reference - https://www.infragistics.com/help/aspnet/webdatagrid-refrence-a-cell-when-creating-an-item-template.
Regards, Hristo Popov