开发者

DataSet Relation over Multiple columns

I'm having a hard time setting relation between my tables in my dataset. I got 2 repeaters (nested). RepeaterReplies is the outer repeater. Here is where I bind it and set the relation.

Here is what I have

            List<DataCol开发者_开发技巧umn> parents = new List<DataColumn>{};
            parents.Add(ds.Tables[0].Columns["REPLY_ID"]);
            parents.Add(ds.Tables[0].Columns["USER_ID"]);
            List<DataColumn> childs = new List<DataColumn>{};
            childs.Add(ds.Tables[2].Columns["REPLY_ID"]);
            childs.Add(ds.Tables[2].Columns["MAKER_USER_ID"]);
            DataColumn[] parentz = parents.ToArray();
            DataColumn[] children = childs.ToArray();
            ds.Relations.Add("parents", parentz, children,false);
            repeaterReplies.DataSource = ds;
            repeaterReplies.DataBind();

When I check my dataset which contains 3 tables (I just need to set a relation between first and last table - tbl[0] and tbl[2]) and I'm sure that first table has the columns REPLY_ID and USER_ID and the 3rd table has REPLY_ID and MAKER_USER_ID.

I'm getting the error when binding the inner repeater (ItemDataBound of outer repeater)

                DataRowView dv = e.Item.DataItem as DataRowView;
                Repeater nestedRepeater = e.Item.FindControl("repeaterComments") as Repeater;
                if (nestedRepeater != null)
                {
                    nestedRepeater.DataSource = dv.CreateChildView("replies");
                    nestedRepeater.DataBind();
                }

Error is

The relation is not parented to the table to which this DataView points.

Thank you


Never tried the CreateChildView method, but shouldn't you use the name you've defined in the DataRelation?

nestedRepeater.DataSource = dv.CreateChildView("parents");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜