This is a migrated thread and some comments may be shown as answers.

[Solved] radgrid many to many

3 Answers 216 Views
Grid
This is a migrated thread and some comments may be shown as answers.
SonicImaging
Top achievements
Rank 1
SonicImaging asked on 07 May 2008, 02:20 PM
Hi,

Are there any examples/docs on dealing with a many to many relation using rad grid.  one to many seems simple but i cant figure out how to deal with many to many.  for example.

catalogDB
id - name
1    catalog1
2    catalog2

categoriesDB
id - name
1    category1
2    category2
3    category3
4    category4

categoriesDB_X_catalogDB
id - catalogID - categoriesID
1       1               1
2       1               3
3       1               2
4       2               3
5       2               4

Thanks
-Keith

3 Answers, 1 is accepted

Sort by
0
Accepted
Yavor
Telerik team
answered on 08 May 2008, 08:25 AM
Hi Keith,

Once you have created the hierarchical structure, it is up to you what data you will pass as a datasource.
For example, if you are using Datasource objects, you "filter" the data via SelectParameters:

.aspx
<asp:AccessDataSource ID="AccessDataSource2" DataFile="~/App_Data/Nwind.mdb" 
SelectCommand="SELECT * FROM Orders Where CustomerID = ?" runat="server">  
            <SelectParameters> 
                <asp:SessionParameter Name="CustomerID" SessionField="CustomerID" Type="string" /> 
            </SelectParameters> 
        </asp:AccessDataSource> 

If you are using the DetailTableDataBind handler, you are still determining which records to pass, based on the key values:

.cs
protected void RadGrid1_DetailTableDataBind(object source, Telerik.Web.UI.GridDetailTableDataBindEventArgs e)  
        {  
            GridDataItem dataItem = (GridDataItem)e.DetailTableView.ParentItem;  
            switch (e.DetailTableView.Name)  
            {  
                case "Orders":  
                    {  
                        string CustomerID = dataItem.GetDataKeyValue("CustomerID").ToString();  
                        e.DetailTableView.DataSource = GetDataTable("SELECT * FROM Orders WHERE CustomerID = '" + CustomerID + "'");  
                        break;  
                    }  
 
                case "OrderDetails":  
                    {  
                        string OrderID = dataItem.GetDataKeyValue("OrderID").ToString();  
                        e.DetailTableView.DataSource = GetDataTable("SELECT * FROM [Order Details] WHERE OrderID = " + OrderID);  
                        break;  
                    }  
            }  
        }  
 

Hence, if you would like to apply some custom logic, you can do so by specifying different criteria. The correspondence, however would always be one to many, in the sense that the masterTable item, which would be expanded to show a detail table, would always be just one.
I hope this information helps.

All the best,
Yavor
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
SonicImaging
Top achievements
Rank 1
answered on 08 May 2008, 01:40 PM
Thanks Yavor,

Thats exactly what I was looking for.  I think i was thinking to deep into it and understand now that when the detail in the grid is displayed its really one to many at that point.

Thanks
-Keith
0
Princy
Top achievements
Rank 2
answered on 09 May 2008, 07:30 AM
Hi Keith,

You can also refer the following demo links.

Hierarchy with DetailTableDataBind event
Hierarchy with declarative relations

Thanks
Princy.
Tags
Grid
Asked by
SonicImaging
Top achievements
Rank 1
Answers by
Yavor
Telerik team
SonicImaging
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or