none
Adding ImageButtonColumn programatically RRS feed

  • Question

  • Hi all, I am rather confused on how one would go about adding an image column programatically. Please note here that I am not doing this via the HTML page but via VB code! Depending on a button clicked I am programatically creating a series of columns then binding the data source to my datagrid. I wish to add an image button as the last column which I can do but I am unable to add an event to it. I tried using .CommandName = "SomeEvent" but no luck. There is no OnClick method for the ImageButton class and was wondering how would I go about doing this?

    Code so far:

                   Dim Col_TempColumn As System.Web.UI.WebControls.BoundColumn 
                   Dim Col_TempImgColumn As System.Web.UI.WebControls.TemplateColumn 
     
                   dg_DataGrid_Temp.AutoGenerateColumns = False 
     
                   Col_TempColumn = New System.Web.UI.WebControls.BoundColumn 
                   Col_TempColumn.DataField = "Column1" 
                   Col_TempColumn.HeaderText = "Column1" 
                   dg_DataGrid_Temp.Columns.Add(Col_TempColumn) 
     
                   Col_TempImgColumn = New System.Web.UI.WebControls.TemplateColumn 
                   Col_TempImgColumn.HeaderText = "" 
                   Col_TempImgColumn.ItemTemplate = New CL_ImageButtonColumn 
                   dg_DataGrid_Temp.Columns.Add(Col_TempImgColumn) 
     
                   dg_DataGrid_Temp.DataSource = Table_DS 
                   dg_DataGrid_Temp.DataBind() 
     
     
     
                Private Class CL_ImageButtonColumn 
                    Implements System.Web.UI.ITemplate 
     
                    Dim ButImg_Temp As New System.Web.UI.WebControls.ImageButton 
     
                    Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements System.Web.UI.ITemplate.InstantiateIn 
                        container.Controls.Add(ButImg_Temp) 
                    End Sub 
     
                End Class 





    Friday, January 9, 2009 3:00 PM