Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspdotnet_website_programming thread: How To add a TemplateColumn with an ImageButton to a DataGrid during run-time (by code)


Message #1 by "Andre Girgner" <Andre@G...> on Tue, 19 Nov 2002 19:25:15
How could I add a TemplateColumn with an ImageButton to a DataGrid during 
run-time (by code) ? It works fine if 'hard-coded' within the HTML section 
of my .aspx file. 

<asp:TemplateColumn HeaderText="Image"> 
<ItemTemplate> 
<asp:ImageButton id="ImageButton1" runat="server" 
OnClick="PagerButtonClick" 
ImageURL="PagerButtonLast.gif" 
CommandArgument='<%# DataBinder.Eval(Container.DataItem, "CompanyName") %
>' 
> 
</asp:ImageButton> 
</ItemTemplate> 
</asp:TemplateColumn> 


I use this code to add a BoundColumn during run-time 

Sub AddBoundColumn(HeaderText As String, DataField As String) 
Dim Column As New BoundColumn() 
With Column 
.HeaderText = HeaderText 
.DataField = DataField 
End With 
ctlDataGrid.Columns.Add(Column) 
End Sub 

Andre 

  Return to Index