Skip to content

Infragistics Community Forum / Web / Ultimate UI for ASP.NET Web Forms / Add button inside webdatagrid columns from code behind

Add button inside webdatagrid columns from code behind

New Discussion
achraf gharbi
achraf gharbi asked on May 14, 2019 10:59 AM

Hi , how can i add a button inside webdatagrid column from code behind ?

Sign In to post a reply

Replies

  • 0
    Hristo Popov
    Hristo Popov answered on May 9, 2019 1:20 PM

    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_5F00_add_5F00_button_5F00_on_5F00_column.zip

    Please, take a look at the topic and the sample and let me know if you have any questions.

    Regards,

    Hristo Popov

    • 0
      achraf gharbi
      achraf gharbi answered on May 10, 2019 7:44 AM

      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 !

      • 0
        Hristo Popov
        Hristo Popov answered on May 14, 2019 10:59 AM

        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

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
achraf gharbi
Favorites
0
Replies
3
Created On
May 14, 2019
Last Post
6 years, 9 months ago

Suggested Discussions

Created by

Created on

May 14, 2019 10:59 AM

Last activity on

Feb 20, 2026 12:47 PM