This is a migrated thread and some comments may be shown as answers.

Add button to child in RadGrid

1 Answer 168 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Hugo
Top achievements
Rank 1
Hugo asked on 17 Jan 2013, 02:44 AM
Hello,

I am evaluating the product, and I have a question.

I have a grid with a parent/child structure

I need to add a button on each child row.

I fill the grid using a run time defined dataset.

I can add a button to the parent using the configuration wizard. So when I bind the dataset to the grid, the button shows together with the parent datatable columns defined in the server.

But when I try to add the button to the child it doesn't work. Only the columns defined in the child datatable appear.

Any help will be greatly appreciated.

Thanks,

Hugo

1 Answer, 1 is accepted

Sort by
0
Angel Petrov
Telerik team
answered on 21 Jan 2013, 01:22 PM
Hi Hugo,

There are a couple of ways that you can add a button to the child items.
  1. Add a GridButtonColumn in the markup of the detail table. More about column types you can find here.
  2. Using OnItemCreated event to dynamically add the button in a template column from the code-behind:
    protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
        {
            if (e.Item is GridDataItem && e.Item.OwnerTableView.ParentItem!=null)
            {
                GridDataItem item = e.Item as GridDataItem;
                Button btn = new Button();
                btn.ID = "SomeId";
                btn.CommandName = "SomeCommandName";
                item["TemplateColumn"].Controls.Add(btn);
            }
        }
  3. You can also add the GridButtonColumn using the configuration wizard(see the attached image). Please note that when adding the button you would have to set the CommandName.

Let me know if I could assist you further.

Regards,
Angel Petrov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Hugo
Top achievements
Rank 1
Answers by
Angel Petrov
Telerik team
Share this question
or