Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding controls to Repeater Control dynamically

Status
Not open for further replies.

Komil13

Programmer
Sep 26, 2001
50
US
Hello

I have a repeater control that is getting results from the database. Now, I would like to dynamically create another repeater control inside the <itemtemplate>. I have placed a PlaceHolder control in the <itemtemplate> tag. I then create a repeater object dynamically, collect additional records that would be displayed in the child repeater object, and try to display it. Everytime I try to add the child repeater object to the Placeholder, I get the following error.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Any Ideas ??
 
I figured that adding code would help. Here is the code from the aspx page:

<asp:Repeater ID="rptCategories" runat="server" >

<itemtemplate>
<table border="0" width="730">
<tr><td class="box2"><span class="regtext"><%# DataBinder.Eval(Container.DataItem, "CategoryID_PK") %> - <%# DataBinder.Eval(Container.DataItem, "Category") %></span><br>
<asp:placeHolder ID="plhSubCategories" runat="server" />
</td></tr>
</table><p>
</itemtemplate>

</asp:Repeater>


Here is the code from the corresponding .vb file:

Sub Page_Load()
'Check if the user has logged in
Check_Cookie()

'Get all the categories from the db.
Dim conCategories as SqlConnection = New SqlConnection( "server=localhost;database=kstore;user id=komil13;pwd=admin13" )
Dim cmdCategories as SqlCommand = New SqlCommand( "Select * From tblCategories", conCategories )
Dim dtrCategories as SqlDataReader

'Open connection, execute the command & assign to the datareader
conCategories.Open()
dtrCategories = cmdCategories.ExecuteReader()

rptCategories.DataSource = dtrCategories
rptCategories.DataBind()

'Close all connections
dtrCategories.Close()
conCategories.Close()
'End Sub

'Sub rptCategories_ItemCreated( s As Object, e As RepeaterItemEventArgs )
'Get all the categories from the db.
Dim conSubCategories as SqlConnection = New SqlConnection( "server=localhost;database=kstore;user id=komil13;pwd=admin13" )
Dim cmdSubCategories as SqlCommand = New SqlCommand( "Select * From tblSubCategories", conSubCategories )
Dim dtrSubCategories as SqlDataReader

'Open connection, execute the command & assign to the datareader
conSubCategories.Open()
dtrSubCategories = cmdSubCategories.ExecuteReader()

dim rpt as Repeater
rpt = New Repeater
rpt.id = "rptSubCategories"
rpt.datasource = dtrSubCategories
rpt.Databind()

plhSubCategories.Controls.Add( rpt )
'Insert the SubCategories

'Close all connections
dtrSubCategories.Close()
conSubCategories.Close()
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top