Link to home
Start Free TrialLog in
Avatar of pstavrinides
pstavrinides

asked on

URGENT!!! Nested repeaters Error

Need Help ASAP got a deadline to meet !! I have two repeaters named categories and subcategories, I fetch two result sets using a stored proceedure and store them in a dataset, in the dataset  a parent table and a child table are created and I have set the relationship between the tables, but.....

My Page breaks at this line of code:
CType(e.Item.FindControl("subcategories"), Repeater).DataSource = CType(e.Item.DataItem, DataRowView).CreateChildView("DRV")

It is producing this error:
System.ArgumentException: The relation is not parented to the table to which this DataView points.

This is the relation declaration:
Dim relation = New DataRelation("DRV", DS.Tables(0).Columns("Grouping"), DS.Tables(1).Columns("Grouping"), True)
DS.Relations.Add(relation)

any ideas ??
Avatar of jef06
jef06
Flag of United States of America image

Dim relation = New DataRelation("DRV", DS.Tables(0).Columns("Grouping"), DS.Tables(1).Columns("Grouping"), False)
At the end put false, you might not have child for all your parent
Avatar of pstavrinides
pstavrinides

ASKER

No difference !!
this is in your OnItemdatabound

CType(e.Item.FindControl("subcategories"), Repeater).DataSource = CType(e.Item.DataItem, DataRowView).CreateChildView("DRV")
CType(e.Item.FindControl("subcategories"), Repeater).DataBind()


In Your Page_load
Dim dst As New DataSet()
Dim sqlda As New SqlDataAdapter("select * from v_catgeorie", sqlconn)
sqlda.Fill(dst, "subscriber")
sqlda = New SqlDataAdapter("select * from v_subctegorie", sqlconn)
sqlda.Fill(dst, "subscription")
Dim relation As DataRelation = New DataRelation("DRV", dst.Tables("v_catgeorie").Columns("Grouping"), dst.Tables("v_subctegorie").Columns("Grouping"))
dst.Relations.Add(relation)
jef06

Thanks for posting...
What I have done is referenced the table in the dataset by ID instead of by table name, but I have also tried to use the default the Table names .Net creates namely "Table" and "Table1", I have used the id because the tables are generated dynamicly and they seem fine, but the error still persists...

I am drawing the data from the same SQL Table through two SQL subqueries in a stored proceedure and then populating the dataset creating two tables within the dataset, I have tested the relationship it has been created, the tables both exist in the dataset and the parent child relationship is there!! .Net supposidly doesnt care where the data comes from, datasets are like mini databases in theory, but in practice I cant get this to work.

This is my OnItemDataBound

Private Sub Categories_OnItemDataBound(ByVal sender As System.Object, ByVal e As RepeaterItemEventArgs) Handles categories.ItemDataBound
        If (e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem) Then
            CType(e.Item.FindControl("subcategories"), Repeater).DataSource = CType(e.Item.DataItem, DataRowView).CreateChildView("DRV")
            CType(e.Item.FindControl("subcategories"), Repeater).DataBind()
        End If
    End Sub
it might be your stored procedure did you had return at the end
Just forget about nesting the Repeaters, handle the OnItemDataBound, and write the sub categories html yourself.  Sometimes, you have to cut your losses, and not be fancy.  Just load the data into a DataRow[] by doing a Select() on the table.  And do a for-loop through the array, and write the html.

ZRH
jef06 Stored proc is fine and returns the results I want, zrh if I was going to do that I wouldnt have posted a question, the point of the nested repeaters and the Data releation between dataset tables is to cut down the overhead of a "Brut Force" loop & dynamic query, the data relation allows for one query instead of one per datarow.
ASKER CERTIFIED SOLUTION
Avatar of pstavrinides
pstavrinides

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You would still be making one query, you would have a dataset with two tables in it, and a relation, you select by that relation using the DataSet.Select() method.  The repeater control obviously must use a loop somewhere in it so there is no extra overhead.  The DataSet.Select() method is called once per datarow of the parent table.  But somehow whether you use a repeater or not your going to have to traverse the relation to get the child tables data.

ZRH
zrh perhaps you should read the question more carefully, I did not have a problem selecting the data, the problem was with the data relation, weather I use select() or a view makes no difference here, the error once again I repeat "System.ArgumentException: The relation is not parented to the table to which this DataView points." ....in addition once again concearning this statement "You would still be making one query...etc", you have not read my comment carefully, again I Quote "the data relation allows for one query instead of one per datarow!" it is the DATA RELATION in question not the repeaters!
Hasn't your problem been solved already?  If not you can read the following article, it seems that you are following it pretty closely already, maybe you can read it closer.
http://authors.aspalliance.com/aylar/ViewArticle.aspx?ArticleID=4&PageID=2

Also, you might want to check to make sure you don't have 2nd, and 3rd parameters of the DataRelation constructor backwards.

ZRH
zrh

it has been solved thanks
Then you might want to close the question
zrh do u pay any attention to any of the comments in this page?? look about five comments up where it sais Administrative Comment and read it !!