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
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
131 ms totalt · 3 externa anrop · v20260731065814-full.b746b907