Click here to Skip to main content
15,879,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
 Public Sub CreateTabl()
        Dim ScrObjects As New ScreenObjects
        Dim buLabl As New Label
        Dim tblBu As New Table
        Dim tr As TableRow
        Dim td As TableCell
        Dim tb As New Table
        'Dim txtbx As TextBox
        Dim ddlst As WebControls.DropDownList

        tb.Font.Size = 10
        tb.BorderWidth = 1
        tb.BorderStyle = BorderStyle.Solid
        tb.CellPadding = 4
        tb.CellSpacing = 0
        tb.ForeColor = Drawing.Color.Black
        tb.Width = 700
        tb.GridLines = GridLines.Both
        tb.Style.Add("align", "center")
        tb.Style.Add("text-align", "center")

        tr = New TableRow
        tr.ID = "trHdr"
        td = New TableCell
        td.Text = "Answer"
        td.ID = "tdAns"
        tr.Controls.Add(td)
        td = New TableCell
        td.Text = "Min Value"
        td.ID = "tdMinValue"
        tr.Controls.Add(td)
        td = New TableCell
        td.Text = "MaxValue"
        td.ID = "tdMaxValue"
        tr.Controls.Add(td)
        td = New TableCell
        td.Text = "Description1"
        td.ID = "tdDescription1"
        tr.Controls.Add(td)
        td = New TableCell
        td.Text = "Description2"
        td.ID = "tdDescription2"
        tr.Controls.Add(td)
        td = New TableCell
        td.Text = "Currency"
        td.ID = "tdCurrency"
        tr.Controls.Add(td)
        td = New TableCell
        td.Text = "Scale Multiplier"
        td.ID = "tdScaleMultiplier"
        tr.Controls.Add(td)
        tb.Controls.Add(tr)
For i As Integer = 1 To ddlst_Scale_Type.SelectedValue
           buLabl = New Label
           buLabl.Text = "lbl" & i
           tr = New TableRow
           tr.ID = "trData_" & i
           td = New TableCell
           td.ID = "tdData_" & i & "0"
           td.Controls.Add(buLabl)
           tr.Controls.Add(td)
           pklst = New IMaCS.Framework.UI.ImacsListControls.PickList.PickListControl
           pklst = ScrObjects.createPKLIST_grid(PickList.PickListTypes.MST_CURRENCY, "pklstProduct" & (i), 100, "", "")
           Me.Controls.Add(pklst)
           td = New TableCell
           td.ID = "tdData_" & i & "1"
           td.Controls.Add(pklst)
           tr.Controls.Add(td)
           pklst = New IMaCS.Framework.UI.ImacsListControls.PickList.PickListControl
           pklst = ScrObjects.createPKLIST_grid(PickList.PickListTypes.MST_BUSINESS_UNIT, "pklstProcess" & (i), 100, "", "")
           td = New TableCell
           td.ID = "tdData_" & i & "2"
           td.Controls.Add(pklst)
           tr.Controls.Add(td)
           pklst = New IMaCS.Framework.UI.ImacsListControls.PickList.PickListControl
           pklst = ScrObjects.createPKLIST_grid(PickList.PickListTypes.MST_RISK_EVENT, "pklstRE" & (i), 100, "", "")
           td = New TableCell
           td.ID = "tdData_" & i & "3"
           td.Controls.Add(pklst)
           tr.Controls.Add(td)
           pklst = New IMaCS.Framework.UI.ImacsListControls.PickList.PickListControl
           pklst = ScrObjects.createPKLIST_grid(PickList.PickListTypes.MST_LOCATION, "pklstSC" & (i), 100, "", "")
           td = New TableCell
           td.ID = "tdData_" & i & "4"
           td.Controls.Add(pklst)
           tr.Controls.Add(td)
           tb.Controls.Add(tr)
       Next

       tr = New TableRow
       td = New TableCell
       td.ColumnSpan = 5
       buLabl = New Label
       buLabl.Text = " "
       td.Controls.Add(buLabl)
       td.BackColor = Drawing.Color.FromName("#c0c0c0")
       tr.Controls.Add(td)
       tb.Controls.Add(tr)

    End Sub


Me.Controls.Add(pklst)

here is the exception occured
Posted
Updated 6-Mar-13 0:16am
v2
Comments
Have you debugged and checked where exactly you are getting this exception ?
If yes, then please mention which line of code exactly that is.

Otherwise we can't just go through this large code and assume what may be causing the problem.
Member 9410081 6-Mar-13 0:52am    
Me.Controls.Add(pklst)

here is the exception occured
ZurdoDev 5-Mar-13 8:10am    
The error tells you what is happening. If you are dynamically adding controls use the Pages OnInit event.
Member 9410081 6-Mar-13 0:53am    
i am adding the controls dynamically ,
i am adding on dropdown selection.
how to resolve this
ZurdoDev 6-Mar-13 6:57am    
You are adding more controls when the dropdown changes? Then I am not sure. Maybe you can preload the controls and then on dropdown change you can make them visible or not. Or possibly during OnInit you can check for IsPostback and then find which control caused the postback and if it is your dropdown then add the controls.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900