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

NeedDataSource not work at Detail table in Self-Reference

6 Answers 157 Views
Grid
This is a migrated thread and some comments may be shown as answers.
louis chan
Top achievements
Rank 1
Iron
louis chan asked on 17 Mar 2010, 05:43 PM
So, here is the code to use needdatasource event, but it seems nothing happen after I expand the sub-category
P.S.: I have changed the sql object to oledb

Code-Behind
Protected Sub RadGrid1_NeedDataSource(ByVal source As ObjectByVal e As GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource 
        Dim cmd As New SqlCommand 
        cmd.CommandText = "SELECT * FROM Products where CategoryID = @CategoryID" 
        RadGrid1.DataSource = GetDataTable(cmd) 
    End Sub 
 
    Public Function GetDataTable(ByVal query As SqlCommand) As DataTable 
        Dim ConnString As String = ConfigurationManager.ConnectionStrings("DBMXCatePro").ConnectionString 
        Dim conn As SqlConnection = New SqlConnection(ConnString) 
        Dim adapter As SqlDataAdapter = New SqlDataAdapter 
        query.Connection = conn 
        adapter.SelectCommand = query 
        Dim table1 As New DataTable 
        conn.Open() 
        Try 
            adapter.Fill(table1) 
        Finally 
            conn.Close() 
        End Try 
        Return table1 
    End Function 


ASP Mark Up:
<asp:AccessDataSource ID="AccessDataSource1" runat="server"  
            DataFile="~/App_Data/dbmx_with_category.mdb"  
            SelectCommand="SELECT * FROM [Categories] where isDelete = false"></asp:AccessDataSource> 
        <asp:AccessDataSource ID="AccessDataSource2" DataFile="~/App_Data/dbmx_with_category.mdb"  
        SelectCommand="SELECT * FROM [Products] where CategoryID= ? and IsDelete=false" runat="server">  
                   <SelectParameters>  
                       <asp:Parameter Name="CategoryID" Type="Int32" />  
                   </SelectParameters>  
        </asp:AccessDataSource>  
        <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateDeleteColumn="True"  
            AutoGenerateEditColumn="True" DataSourceID="AccessDataSource1" GridLines="None"
<MasterTableView AutoGenerateColumns="False" DataKeyNames="categoryID"  
                DataSourceID="AccessDataSource1" HierarchyLoadMode="ServerBind"
<RowIndicatorColumn> 
<HeaderStyle Width="20px"></HeaderStyle> 
</RowIndicatorColumn> 
 
    <SelfHierarchySettings KeyName="categoryID" ParentKeyName="categoryParentID" /> 
    <Columns> 
        <telerik:GridBoundColumn DataField="categoryID" DataType="System.Int32"  
            HeaderText="categoryID" ReadOnly="True" SortExpression="categoryID"  
            UniqueName="categoryID"
        </telerik:GridBoundColumn> 
        <telerik:GridBoundColumn DataField="categoryTitle" HeaderText="categoryTitle"  
            SortExpression="categoryTitle" UniqueName="categoryTitle"
        </telerik:GridBoundColumn> 
        <telerik:GridBoundColumn DataField="categoryIcon" HeaderText="categoryIcon"  
            SortExpression="categoryIcon" UniqueName="categoryIcon"
        </telerik:GridBoundColumn> 
        <telerik:GridBoundColumn DataField="categorySequence" DataType="System.Int32"  
            HeaderText="categorySequence" SortExpression="categorySequence"  
            UniqueName="categorySequence"
        </telerik:GridBoundColumn> 
        <telerik:GridBoundColumn DataField="categoryParentID" DataType="System.Int32"  
            HeaderText="categoryParentID" SortExpression="categoryParentID"  
            UniqueName="categoryParentID"
        </telerik:GridBoundColumn> 
        <telerik:GridCheckBoxColumn DataField="isDelete" DataType="System.Boolean"  
            HeaderText="isDelete" SortExpression="isDelete" UniqueName="isDelete"
        </telerik:GridCheckBoxColumn> 
    </Columns> 
</MasterTableView> 
        </telerik:RadGrid> 

6 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 18 Mar 2010, 10:16 AM
Hello Louis,

Please, find attached a simple working project which demonstrates a similar implementation. Give it a try and let me know if it works for you.

I hope this helps.

Sincerely yours,
Pavlina
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
louis chan
Top achievements
Rank 1
Iron
answered on 18 Mar 2010, 11:13 AM
Hi Pavlina,

It seems that the whole datasource cannot be set with sqldatasource/accessdatasource now but instead of OnNeedDataSource="RadGrid1_NeedDataSource" when I have Self-reference table with other detail-table? Am I right? Thx
0
Pavlina
Telerik team
answered on 18 Mar 2010, 03:37 PM
Hi louis,

This online example shows the self-referencing hierarchy model of Telerik RadGrid. It allows you to build multiple levels of hierarchy from a single table in the data source by specifying relations inside the same table.  You do not need to create separate tables for each child level - one table is sufficient to define the hierarchy schema.  All visual settings will be applied to the nested tables as well.

All the best,
Pavlina
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
louis chan
Top achievements
Rank 1
Iron
answered on 18 Mar 2010, 05:51 PM
Hi Pavlina,

Ya, I have read this example a few days ago. I knew binding vs datasources (sqldatasource/accessdatasource) is working in self-reference, and that's mean in one table. But now, let's say, two tables here, categories and products, the categories may be child of its parent "categories", and the product will belong to the child category or parent category. As a result, in this case there are two tables and using self-referencing.
Until now, what i am understanding that is self-reference one table allow u to use vs datasources, but if u want to bind another detail table when its master table is self-reference, we have to use needdatasource event and no vs datasource can be used here.
Please point me out if I have misunderstanding.

BTW, do u have vb version of yr example? Since it is not correctly converted by some convert c# to vb website.
And...How do I use needdatasource event to bind table into detail table? I know how to use needdatasource binding data into master table.
A lot of questions I have asked, sorry.
Thx a lot.

0
Accepted
Pavlina
Telerik team
answered on 19 Mar 2010, 03:41 PM
Hi Louis,

RadGrid's self-referencing hierarchy functionality has been designed to work with a single flat data table that you assign to RadGrid's DataSouce. I suppose that you want to redefining your detail table data source, which is not a supported scenario in RadGrid.

In order to achieve your goal you could use the advanced hierarchy model of Telerik RadGrid. You can set the table relations programmatically through the GridTableView.ParentTableRelation property. To bind each detail table-view, Telerik RadGrid fires the DetailTableDataBind event.

For more information, please refer to the following online example:
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/detailtabledatabind/defaultcs.aspx

I hope this helps.

All the best,
Pavlina
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
louis chan
Top achievements
Rank 1
Iron
answered on 20 Mar 2010, 05:13 AM
hi Pavlina ,

OK, I have some printscreen and code that need to ask u, so I will create a support ticket. Thx.
Tags
Grid
Asked by
louis chan
Top achievements
Rank 1
Iron
Answers by
Pavlina
Telerik team
louis chan
Top achievements
Rank 1
Iron
Share this question
or