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

DetailTable/Hierarchy linqdatasource not seeing DataKeyName's (sorry about the previous post)

4 Answers 73 Views
Grid
This is a migrated thread and some comments may be shown as answers.
IQworks
Top achievements
Rank 1
IQworks asked on 27 Jan 2009, 01:13 AM

Hi,
I have a hierarchy situation where the child table is not getting data.

this gets the child data, but redisplays it for every mastertable record i expand.
<asp:LinqDataSource ID="LinqDataSource2" runat="server" ContextTypeName="iqLinqDataClassesDataContext"
TableName="WorkoutsDetails" AutoPage="true"
Select="new (wodMemberNo, wodWorkoutNo, wodWorkoutSeq, wodExerciseNo, wodComments)"
</asp:LinqDataSource> 

This gets the child data for each mastertable record as well.
<asp:LinqDataSource ID="LinqDataSource2" runat="server" ContextTypeName="iqLinqDataClassesDataContext"
TableName="WorkoutsDetails" AutoPage="true"
Select="new (wodMemberNo, wodWorkoutNo, wodWorkoutSeq, wodExerciseNo, wodComments)"
Where="wodMemberNo=2 && wodWorkoutNo=2" >
</asp:LinqDataSource>

This gets me an error message that says no child data.
<asp:LinqDataSource ID="LinqDataSource2" runat="server" ContextTypeName="iqLinqDataClassesDataContext"
TableName="WorkoutsDetails" AutoPage="true"
Select="new (wodMemberNo, wodWorkoutNo, wodWorkoutSeq, wodExerciseNo, wodComments)"
Where="wodMemberNo=@wrMemberNo && wodWorkoutNo=@wrNumber" >
<WhereParameters>
<asp:ControlParameter ControlID="RadGrid2" DefaultValue="0"
Name="wrMemberNo" Type="Int32" PropertyName="SelectedValue['wrMemberNo']" />
<asp:ControlParameter ControlID="RadGrid2" DefaultValue="0"
Name="wrNumber" Type="Int32" PropertyName="SelectedValue['wrNumber']" />
</WhereParameters>
</asp:LinqDataSource>

Because ( Where="wodMemberNo=2 && wodWorkoutNo=2" >) gets my child data, it gives me the impression that my Whereparameter and ControlParameter are not picking up the DataKeyNames in my mastertable. 

HERE IS MY RADGRID2 CODE:

<telerik:RadGrid ID="RadGrid2" runat="server" AllowPaging="True" AllowSorting="True" DataSourceID="LinqDataSource2" GridLines="None" ShowGroupPanel="True" Skin="Sunset" AllowAutomaticInserts="True" AllowAutomaticUpdates="True" AllowAutomaticDeletes="True" AutoGenerateDeleteColumn="True" AutoGenerateEditColumn="True"> <HeaderContextMenu EnableTheming="True" Skin="Sunset"> <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> </HeaderContextMenu>
<MasterTableView AutoGenerateColumns="False" CommandItemDisplay="TopAndBottom" DataKeyNames="wrMemberNo,wrNumber" DataSourceID="LinqDataSourceWorkOuts" OnSelectedIndexChanged="radchanged"> <RowIndicatorColumn HeaderText="rOW">
<HeaderStyle Width="20px"></HeaderStyle> </RowIndicatorColumn>
<ExpandCollapseColumn CommandName="lapse"> <HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
<Columns>
<telerik:GridButtonColumn CommandName="Select" Text="Select" /> <telerik:GridBoundColumn DataField="wrMemberNo" DataType="System.Int32" HeaderText="wrMemberNo" SortExpression="wrMemberNo" UniqueName="wrMemberNo" ReadOnly="True">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="wrNumber" DataType="System.Int32" HeaderText="wrNumber"SortExpression="wrNumber" UniqueName="wrNumber" ReadOnly="True"> </telerik:GridBoundColumn>
<
telerik:GridBoundColumn DataField="wrWorkoutName" HeaderText="wrWorkoutName" SortExpression="wrWorkoutName" UniqueName="wrWorkoutName"> </telerik:GridBoundColumn>
<
telerik:GridBoundColumn DataField="wrWorkoutLocationNo" DataType="System.Int32" HeaderText="wrWorkoutLocationNo" SortExpression="wrWorkoutLocationNo" UniqueName="wrWorkoutLocationNo">
</
telerik:GridBoundColumn>
<
telerik:GridBoundColumn DataField="wrWorkoutDescription" HeaderText="wrWorkoutDescription"
SortExpression="wrWorkoutDescription" UniqueName="wrWorkoutDescription"> </telerik:GridBoundColumn>
<
telerik:GridBoundColumn DataField="wrWorkoutTypeNo" DataType="System.Int32" HeaderText="wrWorkoutTypeNo" SortExpression="wrWorkoutTypeNo" UniqueName="wrWorkoutTypeNo"> </telerik:GridBoundColumn>
<
telerik:GridBoundColumn DataField="wrDateCreated" DataType="System.DateTime" HeaderText="wrDateCreated"SortExpression="wrDateCreated" UniqueName="wrDateCreated"> </telerik:GridBoundColumn>
<
telerik:GridBoundColumn DataField="wrDateUpdated" DataType="System.DateTime" HeaderText="wrDateUpdated"SortExpression="wrDateUpdated" UniqueName="wrDateUpdated"> </telerik:GridBoundColumn>
</
Columns>
<
DetailTables>
<
telerik:GridTableView DataKeyNames="wodMemberNo,wodWorkoutNo" DataSourceID="LinqDataSource2" Width="100%" runat="server"> <ParentTableRelation>
<
telerik:GridRelationFields DetailKeyField="wodMemberNo,wodWorkoutNo" MasterKeyField="wrMemberNo,wrNumber" />
</ParentTableRelation>
<RowIndicatorColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn> <ExpandCollapseColumn>
<HeaderStyle Width="20px"></HeaderStyle> </ExpandCollapseColumn>
<Columns>
</Columns>
<
SortExpressions>
<telerik:GridSortExpression FieldName="wodWorkoutSeq"></telerik:GridSortExpression>
</
SortExpressions>
</telerik:GridTableView>
</DetailTables> </MasterTableView>
<ClientSettings AllowDragToGroup="True">
<Scrolling AllowScroll="True" UseStaticHeaders="True" /> </ClientSettings>
<FilterMenu EnableTheming="True" Skin="Sunset">
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> </FilterMenu>
</telerik:RadGrid>

 

 

Thanks for your help.

4 Answers, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 29 Jan 2009, 01:11 PM
Hi David ,

Thank you for the detailed explanation and the code snippets provided.

You need to reference the SelectedValues collection of RadGrid2 instead of SelectedValue as demonstrated in the following online demo of the product:

http://demos.telerik.com/aspnet-ajax/Grid/Examples/Programming/SelectedValue/DefaultCS.aspx (see the SqlDataSource definition for the third grid in the example)

Hence your where parameters signature should be as follows:

<asp:LinqDataSource ID="LinqDataSource2" runat="server" ContextTypeName="iqLinqDataClassesDataContext"   
TableName="WorkoutsDetails" AutoPage="true"   
Select="new (wodMemberNo, wodWorkoutNo, wodWorkoutSeq, wodExerciseNo, wodComments)"   
Where="wodMemberNo=@wrMemberNo && wodWorkoutNo=@wrNumber" >   
<WhereParameters>   
  <asp:ControlParameter ControlID="RadGrid2" DefaultValue="0"   
   Name="wrMemberNo" Type="Int32" PropertyName="SelectedValues['wrMemberNo']" />   
  <asp:ControlParameter ControlID="RadGrid2" DefaultValue="0"   
   Name="wrNumber" Type="Int32" PropertyName="SelectedValues['wrNumber']" />   
</WhereParameters>   
</asp:LinqDataSource> 

Also note that this will work on row click if you enable client selection (ClientSettings -> Selecting -> AllowRowSelect = true), set ClientSettings -> EnablePostBackOnRowClick to true as in the online example above and expand the grid items manually.

Standard hierarchy with expand/collapse from the buttons in the first column will work by setting declarative relations in par with the conventions outlined here:

http://demos.telerik.com/aspnet-ajax/Grid/Examples/Hierarchy/DeclarativeRelations/DefaultCS.aspx
http://www.telerik.com/help/aspnet-ajax/grdhierarchicaldatabindingusingneeddatasource.html

Kind regards,
Sebastian
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
IQworks
Top achievements
Rank 1
answered on 29 Jan 2009, 03:13 PM
Hi Sebastian, 
     Please see my next reply, thanks.
0
IQworks
Top achievements
Rank 1
answered on 29 Jan 2009, 07:58 PM
Hi Sebastian, 
    I tried "SelectedValues" instead of "SelectedValue", but that didnt seem to work, perhaps there is something else going on.  If there is something else you might point out to me? Here is what I used after I got your suggestion:
 

 

<telerik:RadGrid ID="RadGrid2" runat="server" AllowPaging="True" AllowSorting="True"

 

 

DataSourceID="LinqDataSourceWorkOuts" GridLines="None" ShowGroupPanel="True"

 

 

Skin="Sunset" AllowAutomaticInserts="True" AllowAutomaticUpdates="True" AllowAutomaticDeletes="True"

 

 

AutoGenerateDeleteColumn="True" AutoGenerateEditColumn="True" OnSelectedIndexChanged="Radgrid2_select">

 

 

<HeaderContextMenu EnableTheming="True" Skin="Sunset">

 

 

<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>

 

 

</HeaderContextMenu>

 

 

<MasterTableView runat="server" AutoGenerateColumns="False" CommandItemDisplay="TopAndBottom"

 

 

DataKeyNames="wrMemberNo,wrNumber" OnSelectedIndexChanged="radchange" DataSourceID="LinqDataSourceWorkOuts">

 

 

<RowIndicatorColumn HeaderText="rOW">

 

 

<HeaderStyle Width="20px"></HeaderStyle>

 

 

</RowIndicatorColumn>

 

 

<ExpandCollapseColumn CommandName="lapse">

 

 

<HeaderStyle Width="20px"></HeaderStyle>

 

 

</ExpandCollapseColumn>

 

 

<Columns>

 

 

<telerik:GridButtonColumn CommandName="Select" Text="Select" />

 

 

<telerik:GridBoundColumn DataField="wrMemberNo" DataType="System.Int32" HeaderText="wrMemberNo"

 

 

SortExpression="wrMemberNo" UniqueName="wrMemberNo" ReadOnly="False">

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="wrNumber" DataType="System.Int32" HeaderText="wrNumber"

 

 

SortExpression="wrNumber" UniqueName="wrNumber" ReadOnly="False">

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="wrWorkoutName" HeaderText="wrWorkoutName" SortExpression="wrWorkoutName"

 

 

UniqueName="wrWorkoutName">

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="wrWorkoutLocationNo" DataType="System.Int32"

 

 

HeaderText="wrWorkoutLocationNo" SortExpression="wrWorkoutLocationNo" UniqueName="wrWorkoutLocationNo">

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="wrWorkoutDescription" HeaderText="wrWorkoutDescription"

 

 

SortExpression="wrWorkoutDescription" UniqueName="wrWorkoutDescription">

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="wrWorkoutTypeNo" DataType="System.Int32" HeaderText="wrWorkoutTypeNo"

 

 

SortExpression="wrWorkoutTypeNo" UniqueName="wrWorkoutTypeNo">

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="wrDateCreated" DataType="System.DateTime" HeaderText="wrDateCreated"

 

 

SortExpression="wrDateCreated" UniqueName="wrDateCreated">

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="wrDateUpdated" DataType="System.DateTime" HeaderText="wrDateUpdated"

 

 

SortExpression="wrDateUpdated" UniqueName="wrDateUpdated">

 

 

</telerik:GridBoundColumn>

 

 

</Columns>

 

 

<DetailTables>

 

 

<telerik:GridTableView DataSourceID="LinqDataSource2" DataKeyNames="wodMemberNo,wodWorkoutNo"

 

 

Width="100%" runat="server" AutoGenerateRows="False">

 

 

<ParentTableRelation>

 

 

<telerik:GridRelationFields DetailKeyField="wodMemberNo,wodWorkoutNo" MasterKeyField="wrMemberNo,wrNumber" />

 

 

</ParentTableRelation>

 

 

<RowIndicatorColumn>

 

 

<HeaderStyle Width="20px"></HeaderStyle>

 

 

</RowIndicatorColumn>

 

 

<ExpandCollapseColumn>

 

 

<HeaderStyle Width="20px"></HeaderStyle>

 

 

</ExpandCollapseColumn>

 

 

<Columns>

 

 

</Columns>

 

 

<SortExpressions>

 

 

<telerik:GridSortExpression FieldName="wodWorkoutSeq"></telerik:GridSortExpression>

 

 

</SortExpressions>

 

 

</telerik:GridTableView>

 

 

</DetailTables>

 

 

</MasterTableView>

 

 

<ClientSettings AllowDragToGroup="True">

 

 

<Scrolling AllowScroll="True" UseStaticHeaders="True" />

 

 

</ClientSettings>

 

 

<FilterMenu EnableTheming="True" Skin="Sunset">

 

 

<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>

 

 

</FilterMenu>

 

 

</telerik:RadGrid>

 

 

<asp:LinqDataSource ID="LinqDataSource2" runat="server" ContextTypeName="iqLinqDataClassesDataContext"

 

 

TableName="WorkoutsDetails" AutoPage="true" Select="new (wodMemberNo, wodWorkoutNo, wodWorkoutSeq, wodExerciseNo, wodComments)"

 

 

Where="wodMemberNo=@wrMemberNo && wodWorkoutNo=@wrNumber">

 

 

<WhereParameters>

 

 

<asp:ControlParameter ControlID="RadGrid2" DefaultValue="0" Name="wrMemberNo" Type="Int32"

 

 

PropertyName="SelectedValues['wrMemberNo']" />

 

 

<asp:ControlParameter ControlID="RadGrid2" DefaultValue="0" Name="wrNumber" Type="Int32"

 

 

PropertyName="SelectedValues['wrNumber']" />

 

 

</WhereParameters>

 

 

</asp:LinqDataSource>

 

 

<asp:LinqDataSource ID="LinqDataSourceWorkOuts" runat="server" ContextTypeName="iqLinqDataClassesDataContext"

 

 

Where="wrMemberNo=@mbMemberNo " TableName="Workouts" EnableDelete="True" EnableInsert="True"

 

 

EnableUpdate="True" AutoPage="true">

 

 

<WhereParameters>

 

 

<asp:ControlParameter ControlID="RadComboBox2" Name="mbMemberNo" DefaultValue="0"

 

 

Type="Int32" PropertyName="SelectedValue" />

 

 

</WhereParameters>

 

 

</asp:LinqDataSource>

 

 

 

 
  
0
Sebastian
Telerik team
answered on 30 Jan 2009, 08:42 AM
Hi David ,

I would like to draw your attention once again to the last two paragraphs from my previous reply:

Also note that this will work on row click if you enable client selection (ClientSettings -> Selecting -> AllowRowSelect = true), set ClientSettings -> EnablePostBackOnRowClick to true as in the online example above and expand the grid items manually.

Standard hierarchy with expand/collapse from the buttons in the first column will work by setting declarative relations in par with the conventions outlined here:

http://demos.telerik.com/aspnet-ajax/Grid/Examples/Hierarchy/DeclarativeRelations/DefaultCS.aspx
http://www.telerik.com/help/aspnet-ajax/grdhierarchicaldatabindingusingneeddatasource.html

Please revise your code accordingly (choosing merely one of the approaches listed above) and let us know how it goes.

Best regards,
Sebastian
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
IQworks
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
IQworks
Top achievements
Rank 1
Share this question
or