Adding controls dynamically

P

Przemek

Hi,
I'm trying to create menu dynamically (populated with dataset). I want
to have it inside my div, which is inside another div and inside
contentplaceholder. Unfortunately I'm receiving null reference
expetions :/

Here is my aspx code:

<asp:Content ID="Content1" ContentPlaceHolderID="Main" Runat="Server">
<div class="column">
</div>
<div class="page" id="blogs">
<div id="sidebar">
<h3>Choose Category:</h3>
</div>
<div id="content">
<asp:Table ID="BlogTable" runat="server" Width="400px">
</asp:Table>
</div>
</div>
</asp:Content>

and my code-behind responsible for creating menu:

Private Sub RebuildCatView(ByVal ds As DataSet)
Dim catMenu As New Menu
Dim dr As DataRow
For Each dr In ds.Tables(0).Rows
Dim categoryItem As MenuItem = New
MenuItem(CType(dr("Category_Name"), String))
catMenu.Items.Add(categoryItem)
Next
Dim ctrl As New Control
ctrl = Me.FindControl("sidebar")
ctrl.Controls.Add(catMenu)
catMenu.DataBind()
End Sub

I'm receiving my exeption in line:

ctrl.Controls.Add(catMenu)

How can I resolve this problem?

Przemek
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top