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

Update not working in detail table

2 Answers 119 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jon Ingersoll
Top achievements
Rank 1
Jon Ingersoll asked on 28 Jul 2010, 08:12 PM
This is the first time I've tried to make a detail table in a radgrid editable. I have a grid with 3 detail tables. I when I've made one of them updatable so far, but when I enter the new information and hit update the form closes and no data is updated. No error is generated either. I'm using ASP:SqlDataSources for my data. Do I need anything extra to get the details table to run an update?

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="CourseList.ascx.cs" Inherits="edu.yale.som.courses.CourseList" %>
<%@ Register TagPrefix="telerik" Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" %>
<telerik:RadGrid runat="server" ID="GridCourses" AutoGenerateColumns="true" DataSourceID="CourseDataSource"
    Skin="WebBlue" AllowAutomaticUpdates="true">
    <MasterTableView DataKeyNames="SOMCourseID" HierarchyDefaultExpanded="False" AutoGenerateColumns="false"
        ExpandCollapseColumn-Display="true">
        <Columns>
            <telerik:GridBoundColumn DataField="SOMCourseID" UniqueName="SOMCourseID" HeaderText="SOMCourseID"
                Visible="false" />
            <telerik:GridBoundColumn DataField="CourseID" UniqueName="CourseID" HeaderText="CRN" />
            <telerik:GridBoundColumn DataField="NumberSection" UniqueName="CourseNumber" HeaderText="Course Number" />
            <telerik:GridBoundColumn DataField="CourseTitle" UniqueName="Title" HeaderText="Title" />
            <telerik:GridBoundColumn DataField="CourseSession" UniqueName="Session" HeaderText="Session" />
            <telerik:GridBoundColumn DataField="Units" UniqueName="Units" HeaderText="Units" />
            <telerik:GridBoundColumn DataField="TermCode" UniqueName="TermCode" HeaderText="TermCode" />
            <telerik:GridBoundColumn DataField="Cohort" UniqueName="Cohort" HeaderText="Cohort" />
        </Columns>
        <DetailTables>
            <telerik:GridTableView DataKeyNames="SOMCourseID" DataSourceID="CourseTimeDataSource"
                runat="server" AutoGenerateColumns="False" AllowAutomaticUpdates="true">
                <Columns>
                    <telerik:GridBoundColumn DataField="ClassTime" UniqueName="ClassTime" HeaderText="Schedule"
                        ReadOnly="true" />
                    <telerik:GridBoundColumn DataField="Day" UniqueName="Day" HeaderText="Day" Visible="false" />
                    <telerik:GridBoundColumn DataField="StartTime" UniqueName="StartTime" HeaderText="Start Time"
                        Visible="false" />
                    <telerik:GridBoundColumn DataField="EndTime" UniqueName="EndTime" HeaderText="End Time"
                        Visible="false" />
                    <telerik:GridBoundColumn DataField="RecordID" UniqueName="RecordID" HeaderText="RecordID"
                        ReadOnly="true" Visible="true" />
                    <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumnCourseTime" />
                </Columns>
                <EditFormSettings ColumnNumber="1">
                    <FormTableItemStyle Width="100%" Height="29px" />
                    <FormTableStyle GridLines="None" CellPadding="2" CellSpacing="0" />
                    <FormStyle Width="100%" BackColor="#eef2ea" />
                    <EditColumn ButtonType="ImageButton" CancelText="Cancel" UpdateText="Update" InsertText="Add" />
                </EditFormSettings>
                <ParentTableRelation>
                    <telerik:GridRelationFields DetailKeyField="SOMCourseID" MasterKeyField="SOMCourseID" />
                </ParentTableRelation>
            </telerik:GridTableView>
        </DetailTables>
        <DetailTables>
            <telerik:GridTableView DataKeyNames="SOMCourseID" DataSourceID="CourseDescriptionDataSource"
                runat="server" AutoGenerateColumns="False">
                <Columns>
                    <telerik:GridBoundColumn DataField="CourseDescription" UniqueName="Description" HeaderText="Description" />
                </Columns>
                <ParentTableRelation>
                    <telerik:GridRelationFields DetailKeyField="SOMCourseID" MasterKeyField="SOMCourseID" />
                </ParentTableRelation>
            </telerik:GridTableView>
        </DetailTables>
        <DetailTables>
            <telerik:GridTableView DataKeyNames="SOMCourseID" DataSourceID="SpecializationDataSource"
                runat="server" AutoGenerateColumns="False">
                <Columns>
                    <telerik:GridBoundColumn DataField="Specialization" UniqueName="Specialization" HeaderText="Specialization(s)" />
                </Columns>
                <ParentTableRelation>
                    <telerik:GridRelationFields DetailKeyField="SOMCourseID" MasterKeyField="SOMCourseID" />
                </ParentTableRelation>
            </telerik:GridTableView>
        </DetailTables>
        <DetailTables>
            <telerik:GridTableView DataKeyNames="SOMCourseID" DataSourceID="InstructorDataSource"
                runat="server" AutoGenerateColumns="False">
                <Columns>
                    <telerik:GridBoundColumn DataField="LastName" UniqueName="LastName" HeaderText="Last Name" />
                    <telerik:GridBoundColumn DataField="FirstName" UniqueName="FirstName" HeaderText="First Name" />
                    <telerik:GridHyperLinkColumn DataTextField="Email" DataNavigateUrlFields="EmailLink"
                        HeaderText="Email" />
                </Columns>
                <ParentTableRelation>
                    <telerik:GridRelationFields DetailKeyField="SOMCourseID" MasterKeyField="SOMCourseID" />
                </ParentTableRelation>
            </telerik:GridTableView>
        </DetailTables>
    </MasterTableView>
    <FooterStyle HorizontalAlign="Right" Font-Bold="true" />
</telerik:RadGrid>
<asp:SqlDataSource ID="CourseDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:edu_yale_som_courses_dataclasses_connectionString %>"
    ProviderName="System.Data.SqlClient" SelectCommand="Select *, TermCode + CourseID as SOMCourseID, CourseNumber + '-'+ Section as NumberSection from SOMCourses where Termcode = 201003">
</asp:SqlDataSource>
<asp:SqlDataSource ID="CourseTimeDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:edu_yale_som_courses_dataclasses_connectionString %>"
    ProviderName="System.Data.SqlClient" SelectCommand="Select RecordID, SOMCourseID, Day, StartTime, EndTime,  Day + ' ' + StartTime + '-' + EndTime as ClassTime  FROM CourseTime Where SOMCourseID = @SOMCourseID"
    UpdateCommand="Update CourseTime Set Day= '@Day', StartTime='@StartTime', EndTime='@EndTime' WHERE RecordID=@RecordID">
    <SelectParameters>
        <asp:SessionParameter Name="SOMCourseID" SessionField="SOMCourseID" Type="Int64" />
    </SelectParameters>
    <UpdateParameters>
        <asp:Parameter Name="RecordID" Type="Int32" />
    </UpdateParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="CourseDescriptionDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:edu_yale_som_courses_dataclasses_connectionString %>"
    ProviderName="System.Data.SqlClient" SelectCommand="Select *, TermCode + CourseID as SOMCourseID, CourseDescription from SOMCourses where (TermCode + CourseID) = @SOMCourseID ">
    <SelectParameters>
        <asp:SessionParameter Name="SOMCourseID" SessionField="SOMCourseID" Type="Int64" />
    </SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="InstructorDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:edu_yale_som_courses_dataclasses_connectionString %>"
    ProviderName="System.Data.SqlClient" SelectCommand="Select *, 'mailto:'+Email as EmailLink from View_BannerSOMCourseIDInstructorID where SOMCourseID = @SOMCourseID ">
    <SelectParameters>
        <asp:SessionParameter Name="SOMCourseID" SessionField="SOMCourseID" Type="Int64" />
    </SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SpecializationDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:edu_yale_som_courses_dataclasses_connectionString %>"
    ProviderName="System.Data.SqlClient" SelectCommand="Select * from CourseSpecialization where SOMCourseID = @SOMCourseID ">
    <SelectParameters>
        <asp:SessionParameter Name="SOMCourseID" SessionField="SOMCourseID" Type="Int64" />
    </SelectParameters>
</asp:SqlDataSource>

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 29 Jul 2010, 06:58 AM
Hello Jon,

You need to set the DataKeyNames property of the table views in the grid so that the insert, update, and delete operations perform as expected.

ASPX:
<telerik:GridTableView DataKeyNames="SOMCourseID,RecordID" DataSourceID="CourseTimeDataSource"
                runat="server" AutoGenerateColumns="False" AllowAutomaticUpdates="true">

Thanks,
Princy.
0
Jon Ingersoll
Top achievements
Rank 1
answered on 29 Jul 2010, 02:09 PM
Thanks, that did the trick.
Tags
Grid
Asked by
Jon Ingersoll
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Jon Ingersoll
Top achievements
Rank 1
Share this question
or