I am trying to add template columns dynamically to a grid which already has two columns
I used the code
Private Sub Page_Init(sender As Object, e As System.EventArgs) Handles Me.Init
Dim table As New DataTable()
table.Load(get data from database)
For rowCounter As Integer = 0 To table.Rows.Count - 1
For columnCounter As Integer = 0 To table.Columns.Count Step -1
Dim tc As New GridTemplateColumn
tc.HeaderText = "qty_1"
tc.UniqueName = "qty1" & columnCounter.ToString
tc.ItemTemplate = New MyTemplate(tc.UniqueName)
grdSchedule.MasterTableView.Columns.Add(tc)
next
next
End Sub
Private Class MyTemplate
Implements ITemplate
Protected textBox As TextBox
Private colname As String
Public Sub New(ByVal cName As String)
MyBase.New()
colname = cName
End Sub
Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements ITemplate.InstantiateIn
textBox = New TextBox
textBox.ID = "abc"
container.Controls.Add(textBox)
End Sub
End Class
I am able to create columns in the page Init event. But I have a problem using that logic in Init event, as I need to get data which decides the number of columns that need to be created, from database. I want to use it in pageload event.
Can you please help me in this. I am not able to create columns dynamically in pageload event now.
I followed the below posts but all of them are talking about page init event.
http://www.telerik.com/community/forums/aspnet-ajax/grid/problem-creating-radgrid-gridtemplatecolumn-dynamically.aspx
http://www.telerik.com/help/aspnet-ajax/grid-programmatic-creation.html
Thanks,
Kaushik