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

Add ItemTemplate without binding to any fields

1 Answer 65 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mykhaylo
Top achievements
Rank 1
Mykhaylo asked on 13 Jul 2011, 06:30 PM
Hi,

I'm experiencing an issue to add a new column with several buttons there.
Found the article about how to create the item template dynamically, but all those controls are dataBind. (http://www.telerik.com/help/aspnet-ajax/grid-programmatic-creation.html)

So, I have a grid created dynamically and binded to the list of objects (some class).
All columns are created dynamically too, since I need only several class properties to be displayed.
And I need to add one more column to the end of the grid with the 2-3 buttons there and I do not see how to add them without binding to the concrete data field.
Each button's click should raise the event and I should know what exact button was pressed and from which row.

Can you please help me with this?

Thanks,
Myxville

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 14 Jul 2011, 07:47 AM
Hello Mykhaylo,

You can add buttons in ItemTemplate programmatically as shown below.

C#:
public partial class TemplateColumn : ITemplate
{
    public void InstantiateIn(Control container)
    {
        Button btn1 = new Button();
        btn1.ID = "btn1";
        btn1.Click += new EventHandler(btn1_Click);
        btn1.Text = "click";
        container.Controls.Add(btn1);
        Button btn2 = new Button();
        btn.ID="btn2";
        btn2.Click += new EventHandler(btn2_Click);
        btn2.Text = "Help";
        container.Controls.Add(btn2);
     }
     void btn2_Click(object sender, EventArgs e)
    {
       //attaching the event
    }
     void btn1_Click(object sender, EventArgs e)
    {
       //attaching the event
    }
}

Thanks,
Princy.
Tags
Grid
Asked by
Mykhaylo
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or