Hello,
I have to create a DataGrid with dynamic columns and I want to put an ImageButton in a TemplateColumn. If the DataGrid is NOT DYNAMIC, I put this code on the .aspx page like this : (this first part of code is just to explain, it isn't what I want to do)
Now, I want to do it MANUALLY on the page aspx.cs. I have to declare the same type of objects and set the same values, like this :
It doesn't work because I DON'T FIND HOW TO PUT MY IMAGEGUTTON IN THE TEMPLATECOLUMN.
I have to create a DataGrid with dynamic columns and I want to put an ImageButton in a TemplateColumn. If the DataGrid is NOT DYNAMIC, I put this code on the .aspx page like this : (this first part of code is just to explain, it isn't what I want to do)
Code:
<asp:TemplateColumn>
<ItemTemplate>
<asp:ImageButton ID="ibSelect" runat="server" CausesValidation="False"
CommandName="Select" ImageUrl="~/Templates/Images/icon_select.gif" />
</ItemTemplate>
<HeaderStyle Width="16px" />
</asp:TemplateColumn>
It doesn't work because I DON'T FIND HOW TO PUT MY IMAGEGUTTON IN THE TEMPLATECOLUMN.
Code:
TemplateColumn selectTemplate = new TemplateColumn();
ImageButton selectImageButton = new ImageButton();
selectImageButton.ID = "ibSelect";
selectImageButton.CausesValidation = false;
selectImageButton.CommandName = "Select";
selectImageButton.ImageUrl = "~/Templates/Images/icon_select.gif";
Control cselectImageButton = new Control();
cselectImageButton.Controls.Add(selectImageButton);
cselectImageButton.ID = "sel";
selectTemplate.ItemTemplate = (ITemplate) cselectImageButton.Controls[0];
selectTemplate.HeaderStyle.Width = 16;
dg.Columns.Add(selectTemplate);
Comment