Telerk Edit In Place for master table in grids with detail tables throws error
I have a rad grid containing a detail table.  I want to be able to edit in place the rows in the master table and the detail tables.  I have it set up right now the way I think it should be done and I am able to edit the rows in the detail table, but it throws an error when I try to edit a row in the master table.  The error is about the datakey not existing but it is in looking for the datakey from the detail table. This is the actual error:

> SubProgramID is neither a DataColumn nor a DataRelation for table

Here is the code:

ASP.NET

    <asp:Content ID="ContentMain" ContentPlaceHolderID="CPHMain" runat="Server">
    
        
    <div style="text-align: center; width: 100%;">
        <table id="Table5" cellspacing="0" cellpadding="0" width="98%"
            border="0">
            <tr>
                <td height="10">
                    &nbsp;</td>
            </tr>
            <tr>
                <td height="10">
                    <table class="TabTable" cellspacing="0" cellpadding="0" width="100%" border="0">
                        <tr>
                            <td class="SelectedTab" align="center" width="32%" height="30">
                                Programs</td>
                            <td align="center" width="32%" height="30" class="tabPanelTop">&nbsp;</td>
                        </tr>
                    </table>
                   <table id="Table1" cellspacing="0" cellpadding="0" width="100%" border="0" class="SelectedPanel">
                        <tr>
                            <td  align="left" colspan="2">
                                <table cellspacing="0" cellpadding="0" width="100%" border="0">
                                    <tr>
                                        <td align="center" height="10">
                                            <asp:Label ID="lblError" runat="server" Visible="False" CssClass="LabelError" EnableViewState="False">An error has occurred.</asp:Label>
                                            <asp:Panel ID="pnlSystemReview" runat="server" Width="100%">
                                            <table id="Table3" cellspacing="0" cellpadding="0" width="90%" border="0">
                                                <tr height="10px">
                                                    <td colspan="2">
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td colspan="2">
                                                        <telerik:RadGrid ID="rgPrograms" runat="server">
                                                            <MasterTableView DataKeyNames="Program, ProgramID" HierarchyLoadMode="Client" EditMode="InPlace">
                                                                <Columns>
                                                                    <Telerik:GridBoundColumn UniqueName="ProgramID" DataField="ProgramID" visible="false"></Telerik:GridBoundColumn>
                                                                    <Telerik:GridTemplateColumn UniqueName="ProgramDescr" HeaderText="Program" DataType="System.String" DataField="ProgramDescr">
                                                                        <ItemStyle Width="50%"></ItemStyle>
                                                                        <ItemTemplate>
                                                                            <asp:Label ID="lblProgramDesc" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.ProgramDescr") %>'></asp:Label>
                                                                        </ItemTemplate>
                                                                        <EditItemTemplate>
                                                                            <asp:TextBox ID="txtProgramDesc" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.ProgramDescr") %>'
                                                                                MaxLength="200" Width="98%"></asp:TextBox><asp:RequiredFieldValidator ID="rfvProgramDesc"
                                                                                    runat="server" ControlToValidate="txtProgramDesc" ErrorMessage="Please enter a program description.">*</asp:RequiredFieldValidator>
                                                                        </EditItemTemplate>
                                                                    </Telerik:GridTemplateColumn>
                                                                    <Telerik:GridTemplateColumn UniqueName="ProgramCode" HeaderText="Abbreviation" DataType="System.String" DataField="Program">
                                                                        <ItemStyle></ItemStyle>
                                                                        <ItemTemplate>
                                                                            <asp:Label ID="lblProgramCode" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Program") %>'></asp:Label>
                                                                        </ItemTemplate>
                                                                        <EditItemTemplate>
                                                                            <asp:TextBox ID="txtProgramCode" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Program") %>'
                                                                                MaxLength="200" Width="98%"></asp:TextBox><asp:RequiredFieldValidator ID="rfvProgramCode"
                                                                                    runat="server" ControlToValidate="txtProgramCode" ErrorMessage="Please enter a program code.">*</asp:RequiredFieldValidator>
                                                                        </EditItemTemplate>
                                                                    </Telerik:GridTemplateColumn>
                                                                    <telerik:GridTemplateColumn SortExpression="isActive" HeaderText="Active"
                                                                        ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left">
                                                                        <ItemTemplate>
                                                                            <asp:CheckBox ID="cbActive" runat="server" Checked='<%#eval("isActive") %>'
                                                                                        Enabled='False' />
                                                                        </ItemTemplate>
                                                                    </telerik:GridTemplateColumn>
                                                                    <Telerik:GridTemplateColumn UniqueName="Function" AllowFiltering="false">
                                                                        <ItemStyle Wrap="False" HorizontalAlign="Center"></ItemStyle>
                                                                        <ItemTemplate>
                                                                            <asp:ImageButton ID="btnEdit" runat="server" ImageUrl="Common/Images/IconEdit.gif" CommandName="Edit"
                                                                                ToolTip="Edit this record" CausesValidation="False"></asp:ImageButton>
                                                                            <asp:ImageButton ID="btnDelete" runat="server" ImageUrl="Common/Images/IconDelete.gif" CommandName="Delete"
                                                                                ToolTip="Deactivate this record" CausesValidation="False" Visible='<%# Eval("DeleteVisible") %>'></asp:ImageButton>
                                                                            <asp:ImageButton ID="btnActive" runat="server" ImageUrl="~/Common/Images/IconSave.gif" CommandName="Active"
                                                                                ToolTip="Activate this record" CausesValidation="False"  Visible='<%# Eval("ActiveVisible") %>' />     
                                                                        </ItemTemplate>
                                                                        <EditItemTemplate>
                                                                            <asp:ImageButton ID="btnSave" runat="server" ImageUrl="Common/Images/IconSave.gif" CommandName="Update"
                                                                                ToolTip="Save changes"></asp:ImageButton>
                                                                            <asp:ImageButton ID="btnCancel" runat="server" ImageUrl="Common/Images/iconcancel.png" CommandName="Cancel"
                                                                                ToolTip="Cancel changes" CausesValidation="False"></asp:ImageButton>
                                                                        </EditItemTemplate>
                                                                    </Telerik:GridTemplateColumn>
                                                                </Columns>
                                                                <DetailTables>
                                                                    <telerik:GridTableView DataKeyNames="SubProgramID" EditMode="InPlace">
                                                                        <Columns>
                                                                            <Telerik:GridBoundColumn UniqueName="SubProgramID" DataField="SubProgramID" visible="false"></Telerik:GridBoundColumn>
                                                                            <Telerik:GridTemplateColumn UniqueName="SubProgramDescr" HeaderText="SubProgram" DataType="System.String" DataField="ProgramDescr">
                                                                                <ItemStyle Width="50%"></ItemStyle>
                                                                                <ItemTemplate>
                                                                                    <asp:Label ID="lblSubProgramDesc" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.SubProgramDescr") %>'></asp:Label>
                                                                                </ItemTemplate>
                                                                                <EditItemTemplate>
                                                                                    <asp:TextBox ID="txtSubProgramDesc" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.SubProgramDescr") %>'
                                                                                        MaxLength="200" Width="98%"></asp:TextBox><asp:RequiredFieldValidator ID="rfvProgramDesc"
                                                                                            runat="server" ControlToValidate="txtSubProgramDesc" ErrorMessage="Please enter a description.">*</asp:RequiredFieldValidator>
                                                                                </EditItemTemplate>
                                                                            </Telerik:GridTemplateColumn>
                                                                            <Telerik:GridTemplateColumn UniqueName="SubProgramCode" HeaderText="Abbreviation" DataType="System.String" DataField="SubProgram">
                                                                                <ItemStyle></ItemStyle>
                                                                                <ItemTemplate>
                                                                                    <asp:Label ID="lblSubProgramCode" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.SubProgram") %>'></asp:Label>
                                                                                </ItemTemplate>
                                                                                <EditItemTemplate>
                                                                                    <asp:TextBox ID="txtSubProgramCode" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.SubProgram") %>'
                                                                                        MaxLength="200" Width="98%"></asp:TextBox><asp:RequiredFieldValidator ID="rfvProgramCode"
                                                                                            runat="server" ControlToValidate="txtSubProgramCode" ErrorMessage="Please enter a code.">*</asp:RequiredFieldValidator>
                                                                                </EditItemTemplate>
                                                                            </Telerik:GridTemplateColumn>
    
                                                                            <telerik:GridTemplateColumn SortExpression="isActive" HeaderText="Active"
                                                                                ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left">
                                                                                <ItemTemplate>
                                                                                    <asp:CheckBox ID="cbActive" runat="server" Checked='<%#eval("isActive") %>'
                                                                                                Enabled='False' />
                                                                                </ItemTemplate>
                                                                            </telerik:GridTemplateColumn>
                                                                            <Telerik:GridTemplateColumn UniqueName="Function" AllowFiltering="false">
                                                                                <ItemStyle Wrap="False" HorizontalAlign="Center"></ItemStyle>
                                                                                <ItemTemplate>
                                                                                    <asp:ImageButton ID="btnEditSub" runat="server" ImageUrl="Common/Images/IconEdit.gif" CommandName="Edit"
                                                                                        ToolTip="Edit this record" CausesValidation="False"></asp:ImageButton>
                                                                                    <asp:ImageButton ID="btnDeleteSub" runat="server" ImageUrl="Common/Images/IconDelete.gif" CommandName="SubDelete"
                                                                                        ToolTip="Deactivate this record" CausesValidation="False" Visible='<%# Eval("DeleteVisible") %>'></asp:ImageButton>
                                                                                    <asp:ImageButton ID="btnActiveSub" runat="server" ImageUrl="~/Common/Images/IconSave.gif" CommandName="SubActive"
                                                                                        ToolTip="Activate this record" CausesValidation="False"  Visible='<%# Eval("ActiveVisible") %>' />
                                                                                    <asp:hyperlink id="hylManageProgram" runat="server" imageurl="~/Common/Images/bluearrow.gif" 
                                                                                        tooltip="Open Intervention Goals" navigateurl='ml_ProgramDetails.aspx?ProgramID=<%#eval("SubProgramID") %>' />                                            
                                                                                </ItemTemplate>
                                                                                <EditItemTemplate>
                                                                                    <asp:ImageButton ID="btnSaveSub" runat="server" ImageUrl="Common/Images/IconSave.gif" CommandName="SubUpdate"
                                                                                        ToolTip="Save changes"></asp:ImageButton>
                                                                                    <asp:ImageButton ID="btnCancelSub" runat="server" ImageUrl="Common/Images/iconcancel.png" CommandName="SubCancel"
                                                                                        ToolTip="Cancel changes" CausesValidation="False"></asp:ImageButton>
                                                                                </EditItemTemplate>
                                                                            </Telerik:GridTemplateColumn>
                                                                        </Columns>
                                                                    </telerik:GridTableView>
                                                                </DetailTables>
                                                            </MasterTableView>
                                                        </telerik:RadGrid>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td colspan="2">
                                                        &nbsp;</td>
                                                </tr>
                                                <tr>
                                                    <td colspan="2">
                                                        
                                                    </td>
                                                </tr>
                                                
                                            </table>
                                            </asp:Panel>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                          <tr>
                    <td height="15">
                        &nbsp;</td>
                </tr>
                    </table>
                </td>
            </tr>
              <tr>
                    <td height="15">
                        &nbsp;</td>
                </tr>
            </table>
        </div>
    </asp:Content>


VB.NET:



    Partial Class ml_Programs
        Inherits GIC.GlobalPage
    
    
        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            If Not Page.IsPostBack Then
                
            End If
        End Sub
    
        Protected Sub rgPrograms_NeedDataSource(ByVal source As Object, ByVal e As GridNeedDataSourceEventArgs) Handles rgPrograms.NeedDataSource
            Me.rgPrograms.MasterTableView.HierarchyDefaultExpanded = True
            With New GIC.Data.DAL()
                .AddParameter("activeOnly", 0)
                Me.rgPrograms.DataSource = .GetDataTable("pCM_Program_LOAD")
            End With
    
        End Sub
    
        Protected Sub rgPrograms_ItemCommand(ByVal source As Object, ByVal e As GridCommandEventArgs) Handles rgPrograms.ItemCommand
            Select Case e.CommandName
                Case "Delete"
                    delete(e)
                    If Not Me.lblError.Visible Then
                        Me.rgPrograms.Rebind()
                    End If
                Case "Update"
                    Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)
                    Dim ID As String = e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("ProgramID")
                    Dim Code As String = CType(editedItem("ProgramCode").FindControl("txtProgramCode"), TextBox).Text
                    Dim Desc As String = CType(editedItem("ProgramDescr").FindControl("txtProgramDesc"), TextBox).Text
                    saveData(ID, Code, Desc)
                    If Not Me.lblError.Visible Then
                        Me.rgPrograms.Rebind()
                    End If
                Case "Active"
                    delete(e, 1)
                    Me.rgPrograms.Rebind()
                Case "SubDelete"
                    subDelete(e)
                    If Not Me.lblError.Visible Then
                        Me.rgPrograms.Rebind()
                    End If
                Case "SubUpdate"
                    Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)
                    Dim ID As String = e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("SubProgramID")
                    Dim Code As String = CType(editedItem("SubProgramCode").FindControl("txtSubProgramCode"), TextBox).Text
                    Dim Desc As String = CType(editedItem("SubProgramDescr").FindControl("txtSubProgramDesc"), TextBox).Text
                    subSaveData(ID, Code, Desc)
                    If Not Me.lblError.Visible Then
                        Me.rgPrograms.Rebind()
                    End If
                Case "SubActive"
                    subDelete(e, 1)
                    Me.rgPrograms.Rebind()
            End Select
        End Sub
    
        Private Function saveData(ByRef key As String, ByVal code As String, ByVal desc As String) As Boolean
            With New GIC.Data.DAL()
                If Not String.IsNullOrEmpty(key) Then .AddParameter("ProgramID", CInt(key))
                .AddParameter("ProgramDesc", desc)
                .AddParameter("ProgramCode", code)
                If .ExecuteNonQuery("pCM_Program_UPD") Then Return True
            End With
            Me.lblError.Visible = True
            Me.lblError.Text = "Save failed."
            Return False
        End Function
    
        Private Sub delete(ByRef e As GridCommandEventArgs, Optional ByVal active As Integer = 0)
            With New GIC.Data.DAL()
                Dim ID As String = e.Item.Cells(2).Text
                .AddParameter("ProgramID", ID, DbType.Int32)
                If active = 1 Then .AddParameter("Active", 1)
                If Not .ExecuteNonQuery("pCM_Program_DEL") Then
                    Me.lblError.Visible = True
                    Me.lblError.Text = "There was an error deactivating the program."
                End If
            End With
        End Sub
    
        Private Function subSaveData(ByRef key As String, ByVal code As String, ByVal desc As String) As Boolean
            With New GIC.Data.DAL()
                If Not String.IsNullOrEmpty(key) Then .AddParameter("SubProgramID", CInt(key))
                .AddParameter("SubProgramDesc", desc)
                .AddParameter("SubProgramCode", code)
                If .ExecuteNonQuery("pCM_SubProgram_UPD") Then Return True
            End With
            Me.lblError.Visible = True
            Me.lblError.Text = "Save failed."
            Return False
        End Function
    
        Private Sub subDelete(ByRef e As GridCommandEventArgs, Optional ByVal active As Integer = 0)
            With New GIC.Data.DAL()
                Dim ID As String = e.Item.Cells(2).Text
                .AddParameter("SubProgramID", ID, DbType.Int32)
                If active = 1 Then .AddParameter("Active", 1)
                If Not .ExecuteNonQuery("pCM_SubProgram_DEL") Then
                    Me.lblError.Visible = True
                    Me.lblError.Text = "There was an error deactivating the program."
                End If
            End With
        End Sub
    
        Protected Sub rgPrograms_DetailTableDataBind(ByVal source As Object, ByVal e As Telerik.Web.UI.GridDetailTableDataBindEventArgs) Handles rgPrograms.DetailTableDataBind
            Dim parentItem As GridDataItem = CType(e.DetailTableView.ParentItem, GridDataItem)
            If Not parentItem.Edit Then
                Try
                    Dim Program As String = parentItem.OwnerTableView.DataKeyValues(parentItem.ItemIndex).Item("Program")
                    With New GIC.Data.DAL()
                        .AddParameter("activeOnly", 0)
                        .AddParameter("Program", Program)
                        e.DetailTableView.DataSource = .GetDataTable("pCM_SubProgram_LOAD")
                    End With
                    If CType(rgPrograms.DataSource, DataTable).Rows.Count = 1 Then
                        parentItem.Expanded = True
                    End If
                Catch ex As Exception
                    e.DetailTableView.Visible = False
                End Try
            End If
        End Sub
    
    End Class

Telerk Edit In Place for master table in grids with detail tables throws error
===

I have a rad grid containing a detail table.  I want to be able to edit in place the rows in the master table and the detail tables.  I have it set up right now the way I think it should be done and I am able to edit the rows in the detail table, but it throws an error when I try to edit a row in the master table.  The error is about the datakey not existing but it is in looking for the datakey from the detail table. This is the actual error:

> SubProgramID is neither a DataColumn nor a DataRelation for table

Here is the code:

ASP.NET

    <asp:Content ID="ContentMain" ContentPlaceHolderID="CPHMain" runat="Server">
    
        
    <div style="text-align: center; width: 100%;">
        <table id="Table5" cellspacing="0" cellpadding="0" width="98%"
            border="0">
            <tr>
                <td height="10">
                    &nbsp;</td>
            </tr>
            <tr>
                <td height="10">
                    <table class="TabTable" cellspacing="0" cellpadding="0" width="100%" border="0">
                        <tr>
                            <td class="SelectedTab" align="center" width="32%" height="30">
                                Programs</td>
                            <td align="center" width="32%" height="30" class="tabPanelTop">&nbsp;</td>
                        </tr>
                    </table>
                   <table id="Table1" cellspacing="0" cellpadding="0" width="100%" border="0" class="SelectedPanel">
                        <tr>
                            <td  align="left" colspan="2">
                                <table cellspacing="0" cellpadding="0" width="100%" border="0">
                                    <tr>
                                        <td align="center" height="10">
                                            <asp:Label ID="lblError" runat="server" Visible="False" CssClass="LabelError" EnableViewState="False">An error has occurred.</asp:Label>
                                            <asp:Panel ID="pnlSystemReview" runat="server" Width="100%">
                                            <table id="Table3" cellspacing="0" cellpadding="0" width="90%" border="0">
                                                <tr height="10px">
                                                    <td colspan="2">
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td colspan="2">
                                                        <telerik:RadGrid ID="rgPrograms" runat="server">
                                                            <MasterTableView DataKeyNames="Program, ProgramID" HierarchyLoadMode="Client" EditMode="InPlace">
                                                                <Columns>
                                                                    <Telerik:GridBoundColumn UniqueName="ProgramID" DataField="ProgramID" visible="false"></Telerik:GridBoundColumn>
                                                                    <Telerik:GridTemplateColumn UniqueName="ProgramDescr" HeaderText="Program" DataType="System.String" DataField="ProgramDescr">
                                                                        <ItemStyle Width="50%"></ItemStyle>
                                                                        <ItemTemplate>
                                                                            <asp:Label ID="lblProgramDesc" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.ProgramDescr") %>'></asp:Label>
                                                                        </ItemTemplate>
                                                                        <EditItemTemplate>
                                                                            <asp:TextBox ID="txtProgramDesc" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.ProgramDescr") %>'
                                                                                MaxLength="200" Width="98%"></asp:TextBox><asp:RequiredFieldValidator ID="rfvProgramDesc"
                                                                                    runat="server" ControlToValidate="txtProgramDesc" ErrorMessage="Please enter a program description.">*</asp:RequiredFieldValidator>
                                                                        </EditItemTemplate>
                                                                    </Telerik:GridTemplateColumn>
                                                                    <Telerik:GridTemplateColumn UniqueName="ProgramCode" HeaderText="Abbreviation" DataType="System.String" DataField="Program">
                                                                        <ItemStyle></ItemStyle>
                                                                        <ItemTemplate>
                                                                            <asp:Label ID="lblProgramCode" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Program") %>'></asp:Label>
                                                                        </ItemTemplate>
                                                                        <EditItemTemplate>
                                                                            <asp:TextBox ID="txtProgramCode" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Program") %>'
                                                                                MaxLength="200" Width="98%"></asp:TextBox><asp:RequiredFieldValidator ID="rfvProgramCode"
                                                                                    runat="server" ControlToValidate="txtProgramCode" ErrorMessage="Please enter a program code.">*</asp:RequiredFieldValidator>
                                                                        </EditItemTemplate>
                                                                    </Telerik:GridTemplateColumn>
                                                                    <telerik:GridTemplateColumn SortExpression="isActive" HeaderText="Active"
                                                                        ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left">
                                                                        <ItemTemplate>
                                                                            <asp:CheckBox ID="cbActive" runat="server" Checked='<%#eval("isActive") %>'
                                                                                        Enabled='False' />
                                                                        </ItemTemplate>
                                                                    </telerik:GridTemplateColumn>
                                                                    <Telerik:GridTemplateColumn UniqueName="Function" AllowFiltering="false">
                                                                        <ItemStyle Wrap="False" HorizontalAlign="Center"></ItemStyle>
                                                                        <ItemTemplate>
                                                                            <asp:ImageButton ID="btnEdit" runat="server" ImageUrl="Common/Images/IconEdit.gif" CommandName="Edit"
                                                                                ToolTip="Edit this record" CausesValidation="False"></asp:ImageButton>
                                                                            <asp:ImageButton ID="btnDelete" runat="server" ImageUrl="Common/Images/IconDelete.gif" CommandName="Delete"
                                                                                ToolTip="Deactivate this record" CausesValidation="False" Visible='<%# Eval("DeleteVisible") %>'></asp:ImageButton>
                                                                            <asp:ImageButton ID="btnActive" runat="server" ImageUrl="~/Common/Images/IconSave.gif" CommandName="Active"
                                                                                ToolTip="Activate this record" CausesValidation="False"  Visible='<%# Eval("ActiveVisible") %>' />     
                                                                        </ItemTemplate>
                                                                        <EditItemTemplate>
                                                                            <asp:ImageButton ID="btnSave" runat="server" ImageUrl="Common/Images/IconSave.gif" CommandName="Update"
                                                                                ToolTip="Save changes"></asp:ImageButton>
                                                                            <asp:ImageButton ID="btnCancel" runat="server" ImageUrl="Common/Images/iconcancel.png" CommandName="Cancel"
                                                                                ToolTip="Cancel changes" CausesValidation="False"></asp:ImageButton>
                                                                        </EditItemTemplate>
                                                                    </Telerik:GridTemplateColumn>
                                                                </Columns>
                                                                <DetailTables>
                                                                    <telerik:GridTableView DataKeyNames="SubProgramID" EditMode="InPlace">
                                                                        <Columns>
                                                                            <Telerik:GridBoundColumn UniqueName="SubProgramID" DataField="SubProgramID" visible="false"></Telerik:GridBoundColumn>
                                                                            <Telerik:GridTemplateColumn UniqueName="SubProgramDescr" HeaderText="SubProgram" DataType="System.String" DataField="ProgramDescr">
                                                                                <ItemStyle Width="50%"></ItemStyle>
                                                                                <ItemTemplate>
                                                                                    <asp:Label ID="lblSubProgramDesc" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.SubProgramDescr") %>'></asp:Label>
                                                                                </ItemTemplate>
                                                                                <EditItemTemplate>
                                                                                    <asp:TextBox ID="txtSubProgramDesc" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.SubProgramDescr") %>'
                                                                                        MaxLength="200" Width="98%"></asp:TextBox><asp:RequiredFieldValidator ID="rfvProgramDesc"
                                                                                            runat="server" ControlToValidate="txtSubProgramDesc" ErrorMessage="Please enter a description.">*</asp:RequiredFieldValidator>
                                                                                </EditItemTemplate>
                                                                            </Telerik:GridTemplateColumn>
                                                                            <Telerik:GridTemplateColumn UniqueName="SubProgramCode" HeaderText="Abbreviation" DataType="System.String" DataField="SubProgram">
                                                                                <ItemStyle></ItemStyle>
                                                                                <ItemTemplate>
                                                                                    <asp:Label ID="lblSubProgramCode" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.SubProgram") %>'></asp:Label>
                                                                                </ItemTemplate>
                                                                                <EditItemTemplate>
                                                                                    <asp:TextBox ID="txtSubProgramCode" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.SubProgram") %>'
                                                                                        MaxLength="200" Width="98%"></asp:TextBox><asp:RequiredFieldValidator ID="rfvProgramCode"
                                                                                            runat="server" ControlToValidate="txtSubProgramCode" ErrorMessage="Please enter a code.">*</asp:RequiredFieldValidator>
                                                                                </EditItemTemplate>
                                                                            </Telerik:GridTemplateColumn>
    
                                                                            <telerik:GridTemplateColumn SortExpression="isActive" HeaderText="Active"
                                                                                ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left">
                                                                                <ItemTemplate>
                                                                                    <asp:CheckBox ID="cbActive" runat="server" Checked='<%#eval("isActive") %>'
                                                                                                Enabled='False' />
                                                                                </ItemTemplate>
                                                                            </telerik:GridTemplateColumn>
                                                                            <Telerik:GridTemplateColumn UniqueName="Function" AllowFiltering="false">
                                                                                <ItemStyle Wrap="False" HorizontalAlign="Center"></ItemStyle>
                                                                                <ItemTemplate>
                                                                                    <asp:ImageButton ID="btnEditSub" runat="server" ImageUrl="Common/Images/IconEdit.gif" CommandName="Edit"
                                                                                        ToolTip="Edit this record" CausesValidation="False"></asp:ImageButton>
                                                                                    <asp:ImageButton ID="btnDeleteSub" runat="server" ImageUrl="Common/Images/IconDelete.gif" CommandName="SubDelete"
                                                                                        ToolTip="Deactivate this record" CausesValidation="False" Visible='<%# Eval("DeleteVisible") %>'></asp:ImageButton>
                                                                                    <asp:ImageButton ID="btnActiveSub" runat="server" ImageUrl="~/Common/Images/IconSave.gif" CommandName="SubActive"
                                                                                        ToolTip="Activate this record" CausesValidation="False"  Visible='<%# Eval("ActiveVisible") %>' />
                                                                                    <asp:hyperlink id="hylManageProgram" runat="server" imageurl="~/Common/Images/bluearrow.gif" 
                                                                                        tooltip="Open Intervention Goals" navigateurl='ml_ProgramDetails.aspx?ProgramID=<%#eval("SubProgramID") %>' />                                            
                                                                                </ItemTemplate>
                                                                                <EditItemTemplate>
                                                                                    <asp:ImageButton ID="btnSaveSub" runat="server" ImageUrl="Common/Images/IconSave.gif" CommandName="SubUpdate"
                                                                                        ToolTip="Save changes"></asp:ImageButton>
                                                                                    <asp:ImageButton ID="btnCancelSub" runat="server" ImageUrl="Common/Images/iconcancel.png" CommandName="SubCancel"
                                                                                        ToolTip="Cancel changes" CausesValidation="False"></asp:ImageButton>
                                                                                </EditItemTemplate>
                                                                            </Telerik:GridTemplateColumn>
                                                                        </Columns>
                                                                    </telerik:GridTableView>
                                                                </DetailTables>
                                                            </MasterTableView>
                                                        </telerik:RadGrid>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td colspan="2">
                                                        &nbsp;</td>
                                                </tr>
                                                <tr>
                                                    <td colspan="2">
                                                        
                                                    </td>
                                                </tr>
                                                
                                            </table>
                                            </asp:Panel>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                          <tr>
                    <td height="15">
                        &nbsp;</td>
                </tr>
                    </table>
                </td>
            </tr>
              <tr>
                    <td height="15">
                        &nbsp;</td>
                </tr>
            </table>
        </div>
    </asp:Content>


VB.NET:



    Partial Class ml_Programs
        Inherits GIC.GlobalPage
    
    
        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            If Not Page.IsPostBack Then
                
            End If
        End Sub
    
        Protected Sub rgPrograms_NeedDataSource(ByVal source As Object, ByVal e As GridNeedDataSourceEventArgs) Handles rgPrograms.NeedDataSource
            Me.rgPrograms.MasterTableView.HierarchyDefaultExpanded = True
            With New GIC.Data.DAL()
                .AddParameter("activeOnly", 0)
                Me.rgPrograms.DataSource = .GetDataTable("pCM_Program_LOAD")
            End With
    
        End Sub
    
        Protected Sub rgPrograms_ItemCommand(ByVal source As Object, ByVal e As GridCommandEventArgs) Handles rgPrograms.ItemCommand
            Select Case e.CommandName
                Case "Delete"
                    delete(e)
                    If Not Me.lblError.Visible Then
                        Me.rgPrograms.Rebind()
                    End If
                Case "Update"
                    Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)
                    Dim ID As String = e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("ProgramID")
                    Dim Code As String = CType(editedItem("ProgramCode").FindControl("txtProgramCode"), TextBox).Text
                    Dim Desc As String = CType(editedItem("ProgramDescr").FindControl("txtProgramDesc"), TextBox).Text
                    saveData(ID, Code, Desc)
                    If Not Me.lblError.Visible Then
                        Me.rgPrograms.Rebind()
                    End If
                Case "Active"
                    delete(e, 1)
                    Me.rgPrograms.Rebind()
                Case "SubDelete"
                    subDelete(e)
                    If Not Me.lblError.Visible Then
                        Me.rgPrograms.Rebind()
                    End If
                Case "SubUpdate"
                    Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)
                    Dim ID As String = e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("SubProgramID")
                    Dim Code As String = CType(editedItem("SubProgramCode").FindControl("txtSubProgramCode"), TextBox).Text
                    Dim Desc As String = CType(editedItem("SubProgramDescr").FindControl("txtSubProgramDesc"), TextBox).Text
                    subSaveData(ID, Code, Desc)
                    If Not Me.lblError.Visible Then
                        Me.rgPrograms.Rebind()
                    End If
                Case "SubActive"
                    subDelete(e, 1)
                    Me.rgPrograms.Rebind()
            End Select
        End Sub
    
        Private Function saveData(ByRef key As String, ByVal code As String, ByVal desc As String) As Boolean
            With New GIC.Data.DAL()
                If Not String.IsNullOrEmpty(key) Then .AddParameter("ProgramID", CInt(key))
                .AddParameter("ProgramDesc", desc)
                .AddParameter("ProgramCode", code)
                If .ExecuteNonQuery("pCM_Program_UPD") Then Return True
            End With
            Me.lblError.Visible = True
            Me.lblError.Text = "Save failed."
            Return False
        End Function
    
        Private Sub delete(ByRef e As GridCommandEventArgs, Optional ByVal active As Integer = 0)
            With New GIC.Data.DAL()
                Dim ID As String = e.Item.Cells(2).Text
                .AddParameter("ProgramID", ID, DbType.Int32)
                If active = 1 Then .AddParameter("Active", 1)
                If Not .ExecuteNonQuery("pCM_Program_DEL") Then
                    Me.lblError.Visible = True
                    Me.lblError.Text = "There was an error deactivating the program."
                End If
            End With
        End Sub
    
        Private Function subSaveData(ByRef key As String, ByVal code As String, ByVal desc As String) As Boolean
            With New GIC.Data.DAL()
                If Not String.IsNullOrEmpty(key) Then .AddParameter("SubProgramID", CInt(key))
                .AddParameter("SubProgramDesc", desc)
                .AddParameter("SubProgramCode", code)
                If .ExecuteNonQuery("pCM_SubProgram_UPD") Then Return True
            End With
            Me.lblError.Visible = True
            Me.lblError.Text = "Save failed."
            Return False
        End Function
    
        Private Sub subDelete(ByRef e As GridCommandEventArgs, Optional ByVal active As Integer = 0)
            With New GIC.Data.DAL()
                Dim ID As String = e.Item.Cells(2).Text
                .AddParameter("SubProgramID", ID, DbType.Int32)
                If active = 1 Then .AddParameter("Active", 1)
                If Not .ExecuteNonQuery("pCM_SubProgram_DEL") Then
                    Me.lblError.Visible = True
                    Me.lblError.Text = "There was an error deactivating the program."
                End If
            End With
        End Sub
    
        Protected Sub rgPrograms_DetailTableDataBind(ByVal source As Object, ByVal e As Telerik.Web.UI.GridDetailTableDataBindEventArgs) Handles rgPrograms.DetailTableDataBind
            Dim parentItem As GridDataItem = CType(e.DetailTableView.ParentItem, GridDataItem)
            If Not parentItem.Edit Then
                Try
                    Dim Program As String = parentItem.OwnerTableView.DataKeyValues(parentItem.ItemIndex).Item("Program")
                    With New GIC.Data.DAL()
                        .AddParameter("activeOnly", 0)
                        .AddParameter("Program", Program)
                        e.DetailTableView.DataSource = .GetDataTable("pCM_SubProgram_LOAD")
                    End With
                    If CType(rgPrograms.DataSource, DataTable).Rows.Count = 1 Then
                        parentItem.Expanded = True
                    End If
                Catch ex As Exception
                    e.DetailTableView.Visible = False
                End Try
            End If
        End Sub
    
    End Class
