---
title: "Hjälp - Child Repeater"
type: "forum-thread"
url: "https://www.webforum.nu/amne/dotnet/113974-hjälp-child-repeater"
topic: ".NET"
topic_url: "https://www.webforum.nu/amne/dotnet"
author: "Nson"
published: "2004-10-20T08:48:38.000Z"
updated: "2004-10-21T06:06:15.000Z"
replies: 1
views: 270
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/dotnet/113974-hjälp-child-repeater"
---

# Hjälp - Child Repeater

## #1 — Nson, 2004-10-20T08:48Z

Har massivt problem med att få följande enkla sak att fungera.

```
<asp:DataList id="parentDataList" runat="server" DataKeyField="categoryid" OnItemDataBound="DataBind_childRepeater">
					<ItemTemplate>
						<b>
							<%# DataBinder.Eval(Container.DataItem, "categoryname") %>
						</b>
						<br>
						<asp:Repeater runat="server" ID="childRepeater" >
							<ItemTemplate>
								<%# DataBinder.Eval(Container.DataItem, "directoryname") %>
								,
							</ItemTemplate>
						</asp:Repeater>
					</ItemTemplate>
				</asp:DataList>
```

aspx.vb sidan:

```
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here

        Dim sqlParant As New SqlClient.SqlCommand

        sqlParant.CommandText = "SELECT * FROM [dbo].[web.categorys]"

        sqlParant.CommandType = CommandType.Text

        Dim dsParent As DataSet = sqllib.DataSet(sqlParant)

        parentDataList.DataSource = dsParent

        parentDataList.DataBind()
    End Sub

    Public Sub DataBind_childRepeater(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs)

        Dim sqlChild As New SqlClient.SqlCommand

        Dim sqltxt As String = "SELECT * FROM [dbo].[web.categorys] WHERE categoryid='{category_id}'"

        Replace(sqltxt, "{category_id}", parentDataList.DataKeys(parentDataList.SelectedIndex).ToString)

        Dim sql As New SqlClient.SqlCommand

        sql.CommandText = sqltxt

        sql.CommandType = CommandType.Text

        Dim tmpRepeater As Repeater = CType(e.Item.FindControl("childRepeater"), Repeater)

        tmpRepeater.DataSource = sqllib.DataRead(sql)

        tmpRepeater.DataBind()

    End Sub
```

Får hela tiden felet: 

Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index 

Hjälp  :q

Permalänk: https://www.webforum.nu/p/113974

## #2 — Nson, 2004-10-21T06:06Z

Löste det hela genom att:

```
 Public Sub DataBind_childRepeater(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs)

        Dim sqlChild As New SqlClient.SqlCommand

        Dim sqltxt As String = "SELECT * FROM [dbo].[web.directorys] WHERE categoryid='{category_id}'"

        Dim key As Integer = CInt(parentDataList.DataKeys(e.Item.ItemIndex))
        
        Dim sql As New SqlClient.SqlCommand

        Dim sqlComText As String = Replace(sqltxt, "{category_id}", key).ToString

        sql.CommandText = sqlComText

        sql.CommandType = CommandType.Text

        Dim tmpRepeater As Repeater = CType(e.Item.FindControl("childRepeater"), Repeater)

        tmpRepeater.DataSource = sqllib.DataRead(sql)

        tmpRepeater.DataBind()

    End Sub
```

Permalänk: https://www.webforum.nu/p/1465719

---

Tråden på webben: https://www.webforum.nu/amne/dotnet/113974-hjälp-child-repeater
