Radgrid: Problem extracting DataKeyValues from the DataSource

10 posts, 0 answers
  1. Dan
    Dan avatar
    4 posts
    Member since:
    Nov 2012

    Posted 10 Nov 2012 Link to this post

    I am getting the following error: "There was a problem extracting DataKeyValues from the DataSource. Please ensure that DataKeyNames are specified correctly and all fields specified exist in the DataSource."

    I can bind a dataset to my grid and that displays properly.  I have a master table with one detail table.  When I try to put one of the master table rows in edit via clicking on an edit icon in the row and displaying the details in an edit form template, that's when the exception is thrown.

    As you will see the Mastertable datakeynames is CourseId which maps to the element name of the dataset.  Similarly the datakeynames is ChildCourseId for the GridTableView which also maps to the corresponding dataset.

    I have looked at the documentation provided by Telerik and I believe I have coded the page correctly, but I am obviously missing something.  Any insight/suggestions would be greatly appreciated.

    Below are snippets from the aspx page, followed by the code behind and the methods used to build the dataset that is bound to the grid.

    Thanks,
    Dan

    ASPX page:

    <%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Templates/PortalBase.Master" CodeBehind="master_course_list.aspx.vb" Inherits="uo.FacultyPortal.web.course_filter" %>
    <%@ Register Src="~/code/ucMessage.ascx" TagName="Message"    TagPrefix="uc" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="WorkPane" runat="server">
                   <telerik:RadGrid ID="rgCourseInventoryList" runat="server" CssClass="RadGrid" GridLines="None" AllowPaging="True" PageSize="10"
                    AllowSorting="True" AutoGenerateColumns="False" ShowStatusBar="true" OnDetailTableDataBind="rgCourseInventoryList_DetailTableDataBind"
                    OnNeedDataSource="rgCourseInventoryList_NeedDataSource">
                    <MasterTableView CommandItemDisplay="TopAndBottom" DataKeyNames="CourseId" AutoGenerateColumns="false" HierarchyLoadMode="ServerBind"
                    HierarchyDefaultExpanded="true" ClientDataKeyNames="CourseId">
                    <CommandItemSettings AddNewRecordText="<%$ Resources:ui_messages, msgAddNewRecord %>" AddNewRecordImageUrl="../config/Images/Icons/addrecord.gif" RefreshText=""/>
                    <CommandItemTemplate>
                      <asp:ImageButton runat="server" ImageUrl="../config/Images/Icons/addrecord.gif" OnClientClick="return ShowInsertForm();" ID="ibInsertForm" ToolTip="<%$ Resources:ui_labels, ibShowDeleteForm %>"/>
                    </CommandItemTemplate>
     
                    <Columns>
                        <telerik:GridEditCommandColumn EditImageUrl="../config/Images/Icons/edit.png"  ButtonType="ImageButton" ItemStyle-Width="10px" EditText="<%$ Resources:ui_labels, ibEditCourse %>">
                        </telerik:GridEditCommandColumn>
                        <telerik:GridTemplateColumn UniqueName="gtcShowDelete" ItemStyle-Width="10px">
                            <ItemTemplate>
                            <asp:ImageButton runat="server" ImageUrl="../config/Images/Icons/delete.png" ID="ibShowDeleteForm" ToolTip="<%$ Resources:ui_labels, ibShowDeleteForm %>"/>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridBoundColumn UniqueName="CourseCode" HeaderText="<%$Resources:ui_labels, gbcCourseCode %>" DataField="SISCourseCode">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn UniqueName="CourseTitle" DataField="SISCourseTitle" Visible="false">
                        </telerik:GridBoundColumn>
                        <telerik:GridTemplateColumn UniqueName="gtcTitle" HeaderText="<%$ Resources:ui_labels, gtcTitle %>" ItemStyle-VerticalAlign="Middle">
                            <ItemTemplate>
                                <asp:Image ID="imgParent" runat="server" Visible="false" />
                                <asp:Label ID="lblParentTitle" runat="server"></asp:Label>
                                <asp:Label ID="lblCourseTitle" runat="server"></asp:Label>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridBoundColumn UniqueName="CourseNote" HeaderText="<%$Resources:ui_labels, gbcNote %>" DataField="SISCourseNotes">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn UniqueName="CourseExpired" DataField="SISCourseExpired" Visible="false">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn UniqueName="ParentId" DataField="ParentId" Visible="false">
                        </telerik:GridBoundColumn>
                    </Columns>
                    <EditFormSettings EditFormType="Template">
                        <FormTableItemStyle width="100%"></FormTableItemStyle>
                        <FormTableStyle GridLines="None" CellSpacing="0" CellPadding="2"></FormTableStyle>
                        <FormStyle Width="100%" backColor="white"></FormStyle>
                        <FormTemplate>
                            <asp:Table ID="tblCourseDetails" CellSpacing="2" CellPadding="1" runat="server" BorderWidth="1" Width="100%">
                                <asp:TableRow runat="server" ID="trInternal">
                                <asp:TableCell runat="server" ID="tcInternal">
                                <asp:Table ID="tblInternal" runat="server">
                                <asp:TableRow ID="trMessageArea" runat="server">
     
                                    <asp:TableCell ID="tcMessageArea" runat="server" colspan="2">
                                        <uc:Message ID="msgMessageArea" runat="server" />
                                    </asp:TableCell>
                                </asp:TableRow>
                                <asp:TableRow runat="server" ID="trCourseCode">
                                     <asp:TableCell runat="server" ID="tcCourseCode">
                                        <asp:Label runat="server" ID="lblCourseCode" Text="<%$ Resources:ui_labels, lblCourseCode %>"></asp:Label>
                                    </asp:TableCell>
                                    <asp:TableCell runat="server" ID="tcActivityCode2" HorizontalAlign="Left">
                                        <asp:TextBox runat="server" ID="txtSISCourseCode"></asp:TextBox
                                        <asp:Label runat="server" ID="lblCourseCodeMandatory" Text="<%$ Resources:ui_labels, lblMandatoryFlag %>" CssClass="Mandatory"></asp:Label>
                                    </asp:TableCell>
                                </asp:TableRow>
                                <asp:TableRow runat="server" ID="tr1">
                                     <asp:TableCell runat="server" ID="tc1">
                                        <asp:Label runat="server" ID="lblCourseCategory" Text="<%$ Resources:ui_labels, lblCourseCategory %>"></asp:Label>
                                    </asp:TableCell>
                                    <asp:TableCell runat="server" ID="tc2" HorizontalAlign="Left">
                                        <telerik:RadComboBox runat="server" ID="rcbCourseCategory" ></telerik:RadComboBox
                                        <asp:Label runat="server" ID="lblCourseCategoryMandatory" Text="<%$ Resources:ui_labels, lblMandatoryFlag %>" CssClass="Mandatory"></asp:Label>
                                    </asp:TableCell>
                                </asp:TableRow>
                                <asp:TableRow runat="server" ID="tr2">
                                    <asp:TableCell runat="server" ID="tc3">
                                        <asp:Label runat="server" ID="lblCourseType" Text="<%$ Resources:ui_labels, lblCourseType %>"></asp:Label>
                                    </asp:TableCell>
                                    <asp:TableCell runat="server" ID="tc4" HorizontalAlign="Left">
                                        <telerik:RadComboBox runat="server" ID="rcbCourseType" ></telerik:RadComboBox
                                        <asp:Label runat="server" ID="lblCourseTypeMandatory" Text="<%$ Resources:ui_labels, lblMandatoryFlag %>" CssClass="Mandatory"></asp:Label>
                                    </asp:TableCell>
                                </asp:TableRow>
                                <asp:TableRow runat="server" ID="tr3">
                                    <asp:TableCell runat="server" ID="tc5">
                                        <asp:Label runat="server" ID="lblLanguage" Text="<%$ Resources:ui_labels, lblLanguage %>"></asp:Label>
                                    </asp:TableCell>
                                    <asp:TableCell runat="server" ID="tc6" HorizontalAlign="Left">
                                        <telerik:RadComboBox runat="server" ID="rcbLanguage" ></telerik:RadComboBox
                                        <asp:Label runat="server" ID="lblLanguageMandatory" Text="<%$ Resources:ui_labels, lblMandatoryFlag %>" CssClass="Mandatory"></asp:Label>
                                    </asp:TableCell>
                                </asp:TableRow>
                                <asp:TableRow runat="server" ID="tr4">
                                    <asp:TableCell runat="server" ID="tc7">
                                        <asp:Label runat="server" ID="lblAcademicUnit" Text="<%$ Resources:ui_labels, lblAcademicUnit %>"></asp:Label>
                                    </asp:TableCell>   
                                    <asp:TableCell runat="server" ID="tc8" HorizontalAlign="Left">
                                        <telerik:RadComboBox runat="server" ID="rcbAcademicUnit" MarkFirstMatch="true" ></telerik:RadComboBox
                                        <asp:Label runat="server" ID="lblAcademicUnitMandatory" Text="<%$ Resources:ui_labels, lblMandatoryFlag %>" CssClass="Mandatory"></asp:Label>
                                    </asp:TableCell>
                                </asp:TableRow>
                                <asp:TableRow runat="server" ID="tr5">
                                    <asp:TableCell runat="server" ID="tc9">
                                        <asp:Label runat="server" ID="lblNumberOfSessions" Text="<%$ Resources:ui_labels, lblNumberOfSessions %>"></asp:Label>
                                    </asp:TableCell>
                                    <asp:TableCell runat="server" ID="tc10" HorizontalAlign="Left">
                                    <asp:TextBox runat="server" ID="txtNumberOfSessions"></asp:TextBox>
                                    </asp:TableCell>
                                </asp:TableRow>
                                <asp:TableRow runat="server" ID="tr6">
                                    <asp:TableCell runat="server" ID="tc11">
                                        <asp:Label runat="server" ID="lblNote" Text="<%$ Resources:ui_labels, lblNote %>"></asp:Label>
                                    </asp:TableCell>
                                    <asp:TableCell runat="server" ID="tc12" HorizontalAlign="Left">
                                    <asp:TextBox runat="server" ID="txtNote" Wrap="true" TextMode="MultiLine" Rows="4" Columns="40"></asp:TextBox>
                                    </asp:TableCell>
                                </asp:TableRow>
                                <asp:TableRow runat="server" ID="trCrossListCourse">
                                    <asp:TableCell runat="server" ID="tc13">
                                        <asp:Label runat="server" ID="lblCrossListCourseId" Text="<%$ Resources:ui_labels, lblCrossListCourseId %>"></asp:Label>
                                    </asp:TableCell>
                                    <asp:TableCell runat="server" ID="tc14" HorizontalAlign="Left">
                                    <asp:TextBox runat="server" ID="txtCrossListCourseCode"></asp:TextBox>
                                    </asp:TableCell>
                                </asp:TableRow>
                                <asp:TableRow runat="server" ID="tr8">
                                    <asp:TableCell runat="server" id="tc15" HorizontalAlign="Left" ColumnSpan="2">
                                        <asp:Button runat="server" ID="btnUpdate"
                                        Text="<%# IIf((TypeOf(Container) is GridEditFormInsertItem),  Resources.ui_labels.btnAdd.ToString(), Resources.ui_labels.btnUpdate.ToString()) %>"
                                        CommandName='<%# IIf((TypeOf(Container) is GridEditFormInsertItem),  "PerformInsert", "Update") %>' /> 
                                        <asp:Button runat="server" ID="btnCancel" CausesValidation="false" CommandName="Cancel" Text="<%$ Resources:ui_labels, btnCancel %>" />
                                    </asp:TableCell>
                                </asp:TableRow>
                                </asp:Table>
                                </asp:TableCell>
                                </asp:TableRow>
                            </asp:Table>
                        </FormTemplate>
                    </EditFormSettings>
                    <DetailTables>
                        <telerik:GridTableView runat="server" DataKeyNames="ChildCourseId" Name="CrossListView" ClientDataKeyNames="ChildCourseId">
                            <Columns>
                                <telerik:GridButtonColumn ImageUrl="~/config/Images/Icons/lnk_del.png" CommandName="Delete" Text="<%$ Resources:ui_messages, msgDeleteLink %>"
                                UniqueName="gbDeleteLink" ButtonType="ImageButton" ItemStyle-Width="10px" ConfirmText="<%$ Resources:ui_messages, msgConfirmDelete %>" ConfirmDialogType="Classic">
                                </telerik:GridButtonColumn>
                                <telerik:GridTemplateColumn UniqueName="gtcShowDelete" ItemStyle-Width="10px">
                                    <ItemTemplate>
                                        <asp:Image runat="server" ImageUrl="~/config/Images/Icons/lnk_chld.png"/>
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridBoundColumn UniqueName="SISCourseCode" DataField="SISCourseCode">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn UniqueName="SISCourseTitle" DataField="SISCourseTitle">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn UniqueName="SISCourseExpired" DataField="SISCourseExpired" Visible="false">
                                </telerik:GridBoundColumn>
                            </Columns>
                        </telerik:GridTableView>
                    </DetailTables>
                    </MasterTableView>
                    <ClientSettings>
                        <Selecting AllowRowSelect="true"></Selecting>
                        <ClientEvents OnRowDblClick="RowDblClickEdit"></ClientEvents>
                    </ClientSettings>
                </telerik:RadGrid>

    Code behind....

    Imports Telerik.Web.UI
    Imports uo.FacultyPortal.CourseOffer
    Imports uo.FacultyPortal.Admin
    Imports uo.FacultyPortal.Common
    Imports uo.FacultyPortal.Common.Constants
     
    Partial Class course_filter
        Inherits CultureManager
        Private cacheManager As New CacheManager
        Private admin As CD_Tables = New CD_Tables
     
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
     
            If Not Page.IsPostBack Then
     
                bindRadComboBox(rcbAcademicUnit, "CD_Academic_Unit")
                bindRadComboBox(rcbCourseCategory, "CD_Course_Categories")
     
            End If
        End Sub
     
        ''' <summary>
        ''' Return a lst of courses to the user based on their selected criteria
        ''' </summary>
        ''' <param name="sender"></param>
        ''' <param name="e"></param>
        ''' <remarks></remarks>
        Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSearch.Click
     
            msgMessageArea.FlushMessages()
     
            If rcbAcademicUnit.SelectedIndex <= 0 Then
                msgMessageArea.AddMessage(Resources.ui_labels.lblAcademicUnit.ToString + Resources.ui_messages.errRequiredField.ToString,
                             Constants.uoMessageType.ErrorType)
            Else
                rgCourseInventoryList.Rebind()
                rgCourseInventoryList.CurrentPageIndex = 0
     
            End If
     
        End Sub
     
        Protected Sub rgCourseInventoryList_DetailTableDataBind(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridDetailTableDataBindEventArgs) Handles rgCourseInventoryList.DetailTableDataBind
            Dim oCourses As New Course
            Dim oCourseInventory As New DataTable
            Dim parentItem As GridDataItem = CType(e.DetailTableView.ParentItem, GridDataItem)
            If parentItem.Edit Then
                Return
            End If
            If e.DetailTableView.Name = "CrossListView" Then
                Dim courseId As Integer = CInt(parentItem.GetDataKeyValue("CourseId"))
                oCourseInventory = oCourses.getCrossListedCourses(courseId, IIf(cbShowDeleted.Checked, "Y", "N"))
                e.DetailTableView.DataSource = oCourseInventory
     
            End If
     
        End Sub
        ''' <summary>
        ''' Get the data for the grid
        ''' </summary>
        ''' <param name="source"></param>
        ''' <param name="e"></param>
        ''' <remarks></remarks>
        Protected Sub rgCourseInventoryList_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles rgCourseInventoryList.NeedDataSource
            Dim oCourses As New Course
            Dim oCourseInventory As New DataTable
     
            '        Dim a As Integer = rgCourseInventoryList.CurrentPageIndex
            If Not e.IsFromDetailTable Then 'andalso e.RebindReason <> GridRebindReason.InitialLoad Then
                If e.RebindReason <> GridRebindReason.InitialLoad Then
                    oCourseInventory = oCourses.getCourseInventory(rcbAcademicUnit.SelectedValue, rcbCourseCategory.SelectedValue, IIf(cbShowDeleted.Checked, "Y", "N"))
                    rgCourseInventoryList.DataSource = oCourseInventory
     
                End If
     
            End If
     
        End Sub
        ''' <summary>
        ''' If course is no longer offered then overstrike the course code and remove the delete icon
        ''' </summary>
        ''' <param name="source"></param>
        ''' <param name="e"></param>
        ''' <remarks></remarks>
        Protected Sub rgCourseInventory_ItemDataBound(ByVal source As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles rgCourseInventoryList.ItemDataBound
            Dim dataItem As GridDataItem
            Dim headerItem As GridHeaderItem
     
            If TypeOf (e.Item) Is GridDataItem AndAlso e.Item.OwnerTableView.Name = "CrossListView" Then
                dataItem = CType(e.Item, GridDataItem)
                If dataItem("SISCourseExpired").Text <> " " Then
                    CType(dataItem("gbDeleteLink").Controls(0), ImageButton).Visible = False
                    dataItem("SISCourseCode").Font.Strikeout = True
     
                End If
     
                e.Item.OwnerTableView.ShowHeader = False
            End If
     
            If TypeOf (e.Item) Is GridDataItem AndAlso e.Item.OwnerTableView.NamingContainer.ID = "rgCourseInventoryList" Then
                dataItem = CType(e.Item, GridDataItem)
                If dataItem("CourseExpired").Text <> " " Then
                    CType(e.Item.FindControl("ibShowDeleteForm"), ImageButton).Visible = False
                    dataItem("CourseCode").Font.Strikeout = True
     
                End If
                Dim a As String = e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("CourseId")
                If dataItem("ParentId").Text <> " " Then
                    CType(e.Item.FindControl("ibShowDeleteForm"), ImageButton).Visible = False
                    CType(dataItem.FindControl("imgParent"), Image).ImageUrl = "../Images/Icons/lnk.png"
                    CType(dataItem.FindControl("imgParent"), Image).Visible = True
     
                    If dataItem("CourseExpired").Text <> " " Then
                        CType(dataItem.FindControl("lblParentTitle"), Label).Text = "(" + dataItem("ParentId").Text + ")"
                        CType(dataItem.FindControl("lblParentTitle"), Label).Font.Strikeout = True
                        CType(dataItem.FindControl("lblCourseTitle"), Label).Text = "<br>" + dataItem("CourseTitle").Text
                    Else
                        CType(dataItem.FindControl("lblCourseTitle"), Label).Text = "(" + dataItem("ParentId").Text + ")" + "<br>" + dataItem("CourseTitle").Text
                    End If
                Else
                    CType(dataItem.FindControl("lblCourseTitle"), Label).Text = dataItem("CourseTitle").Text
                End If
            ElseIf TypeOf (e.Item) Is GridHeaderItem Then
                headerItem = CType(e.Item, GridHeaderItem)
                '            headerItem
            End If
     
        End Sub
        ''' <summary>
        ''' Take action depending on what type of item it is.
        ''' </summary>
        ''' <param name="source"></param>)
        ''' <param name="e"></param>
        ''' <remarks></remarks>
        Protected Sub rgCourseInventory_ItemCreated(ByVal source As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles rgCourseInventoryList.ItemCreated
            Dim courseId As String
            Dim rcb As New RadComboBox
            Dim oCourses As New Course
     
            If TypeOf e.Item Is GridEditFormItem And e.Item.IsInEditMode Then
     
                bindRadComboBox(CType(e.Item.FindControl("rcbCourseCategory"), RadComboBox), "CD_Course_Categories")
                bindRadComboBox(CType(e.Item.FindControl("rcbCourseType"), RadComboBox), "CD_Course_Types")
                bindRadComboBox(CType(e.Item.FindControl("rcbLanguage"), RadComboBox), "CD_Course_Languages")
                bindRadComboBox(CType(e.Item.FindControl("rcbAcademicUnit"), RadComboBox), "CD_Academic_Unit")
     
                ' Are we editing an existing row?
                If e.Item.ItemIndex >= 0 Then
                    ' Then get the course details from the DB and bind the values to the list boxes.
                    courseId = e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("CourseId")
                    oCourses.getCourseDetails(courseId)
                    ' Hide the course code if we're editing.  Only see it on a create.
                    CType(e.Item.FindControl("trCourseCode"), TableRow).Visible = False
                    CType(e.Item.FindControl("txtSISCourseCode"), TextBox).Text = oCourses.SISCourseCode
                    CType(e.Item.FindControl("rcbCourseCategory"), RadComboBox).SelectedValue = oCourses.CourseCategoryId
                    CType(e.Item.FindControl("rcbCourseType"), RadComboBox).SelectedValue = oCourses.CourseTypeId
                    CType(e.Item.FindControl("rcbLanguage"), RadComboBox).SelectedValue = oCourses.CourseLanguageId
                    CType(e.Item.FindControl("rcbAcademicUnit"), RadComboBox).SelectedValue = oCourses.AcademicUnitId
                    CType(e.Item.FindControl("txtNumberOfSessions"), TextBox).Text = oCourses.NumberOfSessions
                    CType(e.Item.FindControl("txtNote"), TextBox).Text = oCourses.Note
                    If Not oCourses.CrossListCourseCode Is Nothing Then
                        CType(e.Item.FindControl("trCrossListCourse"), TableRow).Visible = False
                    End If
                End If
     
            ElseIf TypeOf e.Item Is GridDataItem Then
                If e.Item.OwnerTableView.NamingContainer.ID = "rgCourseInventoryList" Then
                    Dim clr As String = e.Item.Style("backgroundColor")
                    e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='lightsteelblue';this.style.cursor='hand';")
                    e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='" & clr & "';this.style.cursor='';")
     
                    Dim deleteForm As ImageButton = DirectCast(e.Item.FindControl("ibShowDeleteForm"), ImageButton)
                    deleteForm.Attributes("onclick") = [String].Format("return ShowDeleteForm('{0}','{1}');", e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("CourseId"), e.Item.ItemIndex)
                ElseIf e.Item.OwnerTableView.Name = "CrossListView" Then
                    Dim clr As String = e.Item.Style("backgroundColor")
                    e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='#cc99ff';this.style.cursor='hand';")
                    e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='" & clr & "';this.style.cursor='';")
                End If
            End If
     
            If TypeOf e.Item Is GridDataItem Then
            End If
     
        End Sub
        ''' <summary>
        ''' Hide the empty rows in child gridview
        ''' </summary>
        ''' <param name="sender"></param>
        ''' <param name="e"></param>
        ''' <remarks></remarks>
        Protected Sub rgCourseInventoryList_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles rgCourseInventoryList.PreRender
            HideExpandColumnRecursive(rgCourseInventoryList.MasterTableView)
        End Sub
     
        ''' <summary>
        ''' Recursively loop through grid looking for empty chidren and suppress the "No records found message" and the row.
        ''' </summary>
        ''' <param name="tableView"></param>
        ''' <remarks></remarks>
        Private Sub HideExpandColumnRecursive(ByVal tableView As GridTableView)
            Dim nestedViewItems As GridItem() = tableView.GetItems(GridItemType.NestedView)
            For Each nestedViewItem As GridNestedViewItem In nestedViewItems
                For Each nestedView As GridTableView In nestedViewItem.NestedTableViews
                    If nestedView.Items.Count = 0 Then
                        Dim cell As TableCell = nestedView.ParentItem("ExpandColumn")
                        cell.Controls(0).Visible = False
                        nestedViewItem.Visible = False
                    End If
                    If nestedView.HasDetailTables Then
                        HideExpandColumnRecursive(nestedView)
                    End If
                Next
            Next
        End Sub
    End Class

    ...and the class to build the dataset...

    Option Strict On
     
    Imports System.Data
    Imports uo.Data
    Imports log4net
    Imports uo.FacultyPortal
    Imports uo.FacultyPortal.Common
    Imports System.Globalization
    Imports System.Threading.Thread
    Imports System.Text
     
    Public Class Course
     
        Public Function getCrossListedCourses(ByVal iCourseId As Integer, ByVal iShowDeleted As String) As DataTable
            Dim oCourseCrossList As DataSet
            Dim oGetCourseSchedule As XmlCallWrapper
     
            Try
     
                oGetCourseSchedule = XmlDatabase.CreateCallWrapper("FACULTYPORTAL", "PKG_COURSES.GET_CROSS_LISTED_COURSES_PRC")
                oGetCourseSchedule("PN_COURSE_ID") = iCourseId
                ' TODO need to get language id
                oGetCourseSchedule("PV_SHOW_EXPIRED") = iShowDeleted
                oGetCourseSchedule("PN_INTERFACE_LANG_ID") = 1
                oGetCourseSchedule.Execute()
     
                oCourseCrossList = oGetCourseSchedule.GetDataSet
                oCourseCrossList.Tables("PC_RESULT").Columns(0).ColumnName = "ChildCourseId"
                oCourseCrossList.Tables("PC_RESULT").Columns(1).ColumnName = "SISCourseCode"
                oCourseCrossList.Tables("PC_RESULT").Columns(2).ColumnName = "SISCourseTitle"
                oCourseCrossList.Tables("PC_RESULT").Columns(3).ColumnName = "SISCourseExpired"
     
            Catch ex As Exception
                ' log error
                _logger.Error(ex)
            Finally
     
            End Try
     
            Return oCourseCrossList.Tables("PC_RESULT")
     
        End Function
     
        Public Function getCourseInventory(ByVal iAcademicUnit As Integer, ByVal iCourseCategory As Integer, ByVal iShowDeleted As String) As DataTable
            Dim oCourseSchedule As DataSet
            Dim oGetCourseSchedule As XmlCallWrapper
     
            Try
     
                oGetCourseSchedule = XmlDatabase.CreateCallWrapper("FACULTYPORTAL", "PKG_COURSES.GET_COURSES_BY_UNIT_PRC")
                oGetCourseSchedule("PN_ACADEMIC_UNIT_ID") = iAcademicUnit
                oGetCourseSchedule("PN_COURSE_CATEGORY_ID") = IIf(iCourseCategory = 0, DBNull.Value, iCourseCategory)
                oGetCourseSchedule("PV_SHOW_EXPIRED") = iShowDeleted
                ' TODO - Need to pass in or get the language
                oGetCourseSchedule("PN_INTERFACE_LANG_ID") = 1
                oGetCourseSchedule.Execute()
     
                oCourseSchedule = oGetCourseSchedule.GetDataSet
                oCourseSchedule.Tables("PC_RESULT").Columns(0).ColumnName = "CourseId"
                oCourseSchedule.Tables("PC_RESULT").Columns(1).ColumnName = "SISCourseCode"
                oCourseSchedule.Tables("PC_RESULT").Columns(2).ColumnName = "SISCourseTitle"
                oCourseSchedule.Tables("PC_RESULT").Columns(3).ColumnName = "SISCourseNotes"
                oCourseSchedule.Tables("PC_RESULT").Columns(4).ColumnName = "SISCourseExpired"
                oCourseSchedule.Tables("PC_RESULT").Columns(5).ColumnName = "ParentId"
     
            Catch ex As Exception
                ' log error
                _logger.Error(ex)
            Finally
     
            End Try
     
            Return oCourseSchedule.Tables("PC_RESULT")
        End Function
        Public Sub getCourseDetails(ByVal iCourseId As Integer)
            Dim oCourseDetails As DataSet
            Dim oGetCourseDetails As XmlCallWrapper
     
            Try
                oGetCourseDetails = XmlDatabase.CreateCallWrapper("FACULTYPORTAL", "PKG_COURSES.GET_COURSE_DETAILS_PRC")
                oGetCourseDetails("PN_COURSE_ID") = iCourseId
                oGetCourseDetails.Execute()
                oCourseDetails = oGetCourseDetails.GetDataSet
                CourseCategoryId = CInt(oCourseDetails.Tables("PC_RESULT")(0).Item("COURSE_CATEGORY_ID"))
                CourseTypeId = CInt(oCourseDetails.Tables("PC_RESULT")(0).Item("COURSE_TYPE_ID"))
                CourseLanguageId = CInt(oCourseDetails.Tables("PC_RESULT")(0).Item("LANGUAGE_ID"))
                SISCourseCode = oCourseDetails.Tables("PC_RESULT")(0).Item("SIS_ACAD_ACT_CD").ToString
                AcademicUnitId = CInt(oCourseDetails.Tables("PC_RESULT")(0).Item("UNIT_ID"))
                NumberOfSessions = oCourseDetails.Tables("PC_RESULT")(0).Item("REG_SESSION_COUNT").ToString
                Note = oCourseDetails.Tables("PC_RESULT")(0).Item("NOTE").ToString
                CrossListCourseCode = CStr(oCourseDetails.Tables("PC_RESULT")(0).Item("CROSS_LIST_COURSE_ID"))
            Catch ex As Exception
                ' log error
                _logger.Error(ex)
            Finally
     
            End Try
     
        End Sub
     
    End Class
  2. Andrey
    Admin
    Andrey avatar
    836 posts

    Posted 15 Nov 2012 Link to this post

    Hello,

    I have answered your question in the support thread you have opened. I suggest to continue the discussion there in order to prevent duplicate posts and to avoid confusion.

    All the best,
    Andrey
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. Luis
    Luis avatar
    1 posts
    Member since:
    Jun 2014

    Posted 18 Jun 2014 Link to this post

    I have the same problem, where i cand find the solution you posted
  4. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 19 Jun 2014 in reply to Luis Link to this post

    Hi Luis,

    Please verify if specified DataKeyNames are available in the grid data source. Make sure you have the same name in DataKeyNames as in your DB column name. If this doesn't help, please provide your full code snippet.

    Thanks,
    Princy
  5. Rodney Foley
    Rodney Foley avatar
    72 posts
    Member since:
    Oct 2009

    Posted 22 Feb 2019 in reply to Andrey Link to this post

    Hi @Andrey,

    I now this is an old thread however it is kind of rude to kill a public thread and take it private. Yes they opened two when they should have just did one or the other. However the public should be where a solution is come to so that you can share it.

    What was the solution that fixed this specific issue?

  6. Peter Milchev
    Admin
    Peter Milchev avatar
    804 posts

    Posted 27 Feb 2019 Link to this post

    Hello Rodney,

    Taking a thread private is not done with the intention of killing the public thread but the private threads allow the customer to attach a project and provide sensitive data privately if needed. That helps a lot in the investigation process. 

    What we are aiming to do is once we have a solution to share it in the originating forum thread for convenience and better visibility from the community. 

    In this case, we missed sharing the answer and I will provide a summary of the private thread now: 

    The issue is that in the DetailTableDataBind event an incorrect if statement returns when in edit mode. Once the if check is removed, the issue is resolved: 

    Protected Sub rgCourseInventoryList_DetailTableDataBind(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridDetailTableDataBindEventArgs) Handles rgCourseInventoryList.DetailTableDataBind
            Dim oCourses As New Course
            Dim oCourseInventory As New DataTable
            Dim parentItem As GridDataItem = CType(e.DetailTableView.ParentItem, GridDataItem)
         ' remove the   If parentItem.Edit to fix the issue
         '    If parentItem.Edit Then
         '        Return
         '   End If
            If e.DetailTableView.Name = "CrossListView" Then
                Dim courseId As Integer = CInt(parentItem.GetDataKeyValue("CourseId"))
                oCourseInventory = oCourses.getCrossListedCourses(courseId, IIf(cbShowDeleted.Checked, "Y", "N"))
                e.DetailTableView.DataSource = oCourseInventory
      
            End If
      
        End Sub


    Regards,
    Peter Milchev
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  7. Rodney Foley
    Rodney Foley avatar
    72 posts
    Member since:
    Oct 2009

    Posted 27 Feb 2019 Link to this post

    Hi Peter,

    I understand why it is taken private, however none of those reasons apply here as he posted all his source publicly. The bug was in his code. And it doesn't answer the topic of the thread, as he was doing it correctly but had code that blocked him getting to the section. Which is a debug error that he clearly didn't step through the code. :)  I find my issue and resolved it and this thread in the end was not related to my issue, however if the answer was posted it would have quickened my resolution to be honest.

    Seems instead of saying just I answered you privately, they could have posted the same answer twice, or told the private one I answered you publicly.   As this situation is the user posting it twice with full information nothing needed to be private from their POV. 

    Good intentions are great, however that is all they are, actions are what people actually see. If they don't align with a persons or companies intentions then people will infer intentions base don the visible actions.  if it takes 5 years to share the answer, and only after prompting, I would say the thread was killed by the actions at the time and one can only infer intentions based on what is visible to them.

     

  8. Peter Milchev
    Admin
    Peter Milchev avatar
    804 posts

    Posted 04 Mar 2019 Link to this post

    Hello Rodney,

    Yes, I agree that this is not a good practice to leave the public thread with no answer and we are aiming to always share a summary of the solution in the public thread which is more visible in the recent years' threads. 

    On the other hand, going private cannot be always avoided, as sometimes a few replies and fully runnable projects are required to track down an issue, as it is the case with this scenario, and duplicating all the answers would be tiresome and would worsen the readability of the forum thread for the community. 

    Generally, we are striving to improve our products and services, so any constructive feedback is greatly appreciated. For example, the Customer Service form we have is designed for sharing your overall impressions about our company, products, support service, marketing, events, websites, etc.

    Again, thank you for your feedback, it is taken into account and appreciated and we have already introduced internal practices to always share the solution summary with the community. 

    Regards,
    Peter Milchev
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  9. Rahul
    Rahul avatar
    5 posts
    Member since:
    May 2019

    Posted 30 Jun Link to this post

    Hi Peter,

    I am also facing the issues while adding DataKeyNames. I am creating the grid dynamically and assigning the List of ExpandoObject as datasource of grid.

     

  10. Jon
    Jon avatar
    30 posts
    Member since:
    Apr 2009

    Posted 02 Jul Link to this post

    Got the same issue:

     

    Grid Code:

    <telerik:RadGrid ID="RadGrid1" RenderMode="Lightweight" AllowPaging="true" AllowSorting="True"
        AllowFilteringByColumn="True" ShowStatusBar="false" CommandItemDisplay="Top" Skin="Bootstrap"
        PageSize="50" DataSourceID="SqlDataSource1" GridLines="None"  AllowAutomaticInserts="True"      
        AutoGenerateColumns="false" runat="server" EnableLinqExpressions="False" CellSpacing="0"
        ShowFooter="True" ShowHeader="true" Width="100%">
        <ClientSettings AllowKeyboardNavigation="true"></ClientSettings>
        <GroupingSettings CaseSensitive="false" />
        <MasterTableView DataKeyNames="Cart_SessionID">
            <Columns>
                <telerik:GridBoundColumn DataField="Cart_SessionID" HeaderText="Session ID" UniqueName="Cart_SessionID"
                    ShowFilterIcon="false" AutoPostBackOnFilter="true">
                    <HeaderStyle Width="200px" />
                </telerik:GridBoundColumn>
     
                <telerik:GridBoundColumn DataField="Cart_Date" HeaderText="Date" DataFormatString="{0:dd/MM/yyyy}" UniqueName="Cart_Date"
                    ShowFilterIcon="false" AutoPostBackOnFilter="true">
                    <HeaderStyle Width="150px" />
                </telerik:GridBoundColumn>
                                 
                <telerik:GridBoundColumn DataField="Items" HeaderText="Total Items" UniqueName="Items"
                 AllowFiltering="false">
                </telerik:GridBoundColumn>
     
                <telerik:GridTemplateColumn HeaderText="" AllowFiltering="false" >
                    <ItemTemplate>
                        <a data-uuid='<%#Eval("Cart_SessionID")%>' title="Add to Cart" class='crquote btn btn-success' runat="server" id="QuoteButt"><i class="fa fa-shopping-cart"></i> Add To Cart</a>                                                               
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
            </Columns>
                <DetailTables>
                    <telerik:GridTableView DataKeyNames="Cart_SessionID" DataSourceID="DSRelated" Width="100%" runat="server" CommandItemDisplay="None" ShowHeader="true" AllowFilteringByColumn="false" Name="Child">
                        <NoRecordsTemplate>No items listed....</NoRecordsTemplate>
                        <ParentTableRelation>
                            <telerik:GridRelationFields DetailKeyField="Cart_SessionID" MasterKeyField="Cart_SessionID" />
                        </ParentTableRelation>
                        <Columns>
                            <telerik:GridTemplateColumn HeaderText="Products" UniqueName="Products">
                                <ItemTemplate>
                                    <%# Eval("Cart_Qty")%> x <%# Eval("Cart_STKCode")%> - <%# Eval("Cart_Title")%><br />
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
                        </Columns>
                        <SortExpressions>
                            <telerik:GridSortExpression FieldName="Cart_STKCode" SortOrder="Descending"></telerik:GridSortExpression>
                        </SortExpressions>
                    </telerik:GridTableView>                   
                </DetailTables>
        </MasterTableView>
        <PagerStyle Mode="NextPrev" AlwaysVisible="true" />
    </telerik:RadGrid>

     

    Data source Markup

     

     

            <asp:SqlDataSource ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:system %>" runat="server" ProviderName="MySql.Data.MySqlClient"
                SelectCommand="User_Cart" SelectCommandType="StoredProcedure"></asp:SqlDataSource>
     
    <asp:SqlDataSource ID="DSRelated" ConnectionString="<%$ ConnectionStrings:system %>" runat="server" ProviderName="MySql.Data.MySqlClient"
        SelectCommand="User_Cart_Items" SelectCommandType="StoredProcedure">
        <SelectParameters>
            <asp:Parameter Name="Cart_SessionID" Type="string" />
        </SelectParameters>                                       
        </asp:SqlDataSource>

     

    Yet still get the data Key name error

    Both DB quires have 'Cart_SessionID' in it

Back to Top