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

[Solved] Detail tables DataKeyValues count = 0

1 Answer 89 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 16 May 2009, 10:02 PM
Hello,

I've got a nested grid that looks like this...

        <telerik:RadGrid ID="gridAllocations" runat="server" ShowHeader="false" 
            DataSourceID="dsComponentAllocationGroups"
            <MasterTableView AutoGenerateColumns="False" DataSourceID="dsComponentAllocationGroups" DataKeyNames="AllocationGroupID" HierarchyDefaultExpanded="True"
            <RowIndicatorColumn> 
            <HeaderStyle Width="20px"></HeaderStyle> 
            </RowIndicatorColumn> 
 
            <ExpandCollapseColumn> 
            <HeaderStyle Width="20px"></HeaderStyle> 
            </ExpandCollapseColumn> 
                <Columns> 
                    <telerik:GridTemplateColumn DataField="AllocationGroupDescription"  
                        HeaderText="AllocationGroupDescription"  
                        SortExpression="AllocationGroupDescription"  
                        UniqueName="AllocationGroupDescription"
                        <ItemTemplate> 
                            <asp:label runat="server" ID="lblAllocationTitle" Text='<%# Eval("AllocationGroupDescription") & " - Your allocation is " & Decimal.Round(Eval("Allocation"),1) & " units."%>' Font-Bold="true"></asp:label> 
                        </ItemTemplate> 
                    </telerik:GridTemplateColumn> 
                </Columns> 
                <DetailTables> 
        <telerik:GridTableView runat="server" Name="gridParentItems" AutoGenerateColumns="False" ShowHeader="true"  
            DataSourceID="dsFinalItems" GridLines="None" Skin="Default" 
             DataKeyNames="ConferenceSubmissionItemID,ConferenceSubmissionItemSponsorshipID"
            <RowIndicatorColumn Visible="False"
            <HeaderStyle Width="20px"></HeaderStyle> 
            </RowIndicatorColumn> 
 
            <ExpandCollapseColumn Visible="False" Resizable="False"
            <HeaderStyle Width="20px"></HeaderStyle> 
            </ExpandCollapseColumn> 
            <ParentTableRelation> 
                <telerik:GridRelationFields MasterKeyField="AllocationGroupID" DetailKeyField="AllocationGroupID" /> 
            </ParentTableRelation> 

I have a button in the gridParentItems grid, and when I click it I want to get the ConferenceSubmissionItemSponsorshipID for the given item. I then use this code to allow a user to change the order of an item in the db...

    Protected Sub lnkMoveDown_Click(ByVal sender As ObjectByVal e As System.EventArgs) 
        Try 
            Dim curGridItem As GridItem = CType(CType(sender, LinkButton).Parent.Parent, GridItem) 
            Dim sponsorID As Integer 
            Dim itemsGrid As Telerik.Web.UI.GridTableView 
            itemsGrid = Me.gridAllocations.MasterTableView.DetailTables(0) 
            sponsorID = itemsGrid.DataKeyValues(curGridItem.ItemIndex)("ConferenceSubmissionItemSponsorshipID"
            Dim curSponsor As New ISAConferenceSubmissionItemSponsor(sponsorID) 
            curSponsor.ChangeComponentOrder(CInt(Me.lblActiveComponent.Text), CInt(CType(sender, LinkButton).CommandArgument) + 1) 
            Me.gridAllocations.DataBind() 
        Catch 
        End Try 
    End Sub 

The problem is that the itemsGrid.DataKeyValues has a count of 0. I know that the ConferenceSubmissionItemSponsorshipID is there - it'll show in the table if I add it as a column, so I can't figure out why it's not filling.

Does anybody have any ideas - I'm probably missing something obvious here, but it would really be helpful if I could figure this out because I use similar code in a few other places on the page and am having the same problems there...

Thanks,

Mike

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 18 May 2009, 10:01 AM
Hi Mike,

Try accessing the DataKeyValue for the corresponding row in the following manner and see whether it helps.

VB:

Dim
 curGridItem As GridDataItem = DirectCast(DirectCast(sender, LinkButton).Parent.Parent, GridDataItem) 
 sponsorID = curGridItem.GetDataKeyValue("ConferenceSubmissionItemSponsorshipID").ToString() 

Princy.
Tags
Grid
Asked by
Mike
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or