More Issues with AllowAutomaticUpdates property

2 posts, 0 answers
  1. EmpowerIT
    EmpowerIT avatar
    117 posts
    Member since:
    Jun 2007

    Posted 17 Jan 2008 Link to this post

    Hi,
    I think i've stumbled upon another problem with the AllowAutomaticUpdates property.
    Are these properties only meant to work if you set the DataSourceId declaratively? I've done some testing and that seems the case, because if i set the datasource in the NeedDataSource event, automatic updates don't seem to work.

    This is my code:

    1  void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)  
    2     {  
    3         if (!e.IsFromDetailTable)  
    4         {  
    5             string typeID = Request["typeId"];  
    6             if (Convert.ToInt32(typeID) == "1")  
    7             {  
    8                 RadGrid1.MasterTableView.DataSource = JobsSourceSuburb;  
    9             }  
    10             else 
    11             {  
    12                 RadGrid1.MasterTableView.DataSource = JobsSourceTech;  
    13             }  
    14         }  
    15     } 

    This is my Datasource definition:


    1   <asp:SqlDataSource ID="JobsSourceTech" runat="server" ConnectionString="<%$ ConnectionStrings:MyConnectionString %>" 
    2             ProviderName="System.Data.SqlClient" OldValuesParameterFormatString="original_{0}" 
    3             SelectCommand="SELECT * FROM [View_test_RadSchedulerDetails] WHERE [TechnicianId] = @TechnicianId AND [ScheduleDate] = @ScheduleDate"   
    4             UpdateCommand="UPDATE [Jobs] SET [Vacant] = @Vacant, [Recall] = @Recall, [Confirmed] = @Confirmed WHERE [JobId] = @original_JobId" 
    5             ConflictDetection="CompareAllValues">  
    6            <SelectParameters> 
    7             <asp:Parameter Name="TechnicianId" Type="Int32" Direction="Input"/>  
    8             <asp:Parameter Name="ScheduleDate" Type="DateTime" Direction="Input" /> 
    9             </SelectParameters> 
    10             <UpdateParameters> 
    11             <asp:Parameter Name="original_JobId" Type="Int32" /> 
    12             <asp:Parameter Name="Recall" Type="Boolean"  /> 
    13             <asp:Parameter Name="Vacant" Type="Boolean"  /> 
    14             <asp:Parameter Name="Confirmed" Type="Boolean" /> 
    15             </UpdateParameters> 
    16   </asp:SqlDataSource> 
    17           
    18         <asp:SqlDataSource ID="JobsSourceSuburb" runat="server" ConnectionString="<%$ ConnectionStrings:MyConnectionString %>" 
    19             ProviderName="System.Data.SqlClient"   
    20             SelectCommand="SELECT * FROM [View_test_RadSchedulerDetails] WHERE [SuburbId] = @SuburbId AND [ScheduleDate] = @ScheduleDate" 
    21             UpdateCommand="UPDATE [Jobs] SET [Vacant] = @Vacant, [Recall] = @Recall, [Confirmed] = @Confirmed WHERE [JobId] = @original_JobId" 
    22             ConflictDetection="CompareAllValues">  
    23            <SelectParameters> 
    24             <asp:Parameter Name="SuburbId" Type="Int32" Direction="Input"/>  
    25             <asp:Parameter Name="ScheduleDate" Type="DateTime" Direction="Input" /> 
    26             </SelectParameters> 
    27             <UpdateParameters> 
    28             <asp:Parameter Name="JobId" Type="Int32" /> 
    29             <asp:Parameter Name="Recall" Type="Boolean"  /> 
    30             <asp:Parameter Name="Vacant" Type="Boolean"  /> 
    31             <asp:Parameter Name="Confirmed" Type="Boolean" /> 
    32             </UpdateParameters> 
    33         </asp:SqlDataSource> 

    This is my RadGrid definition (its a slightly large one):

    1  <telerik:RadGrid ID="RadGrid1" runat="server" Skin="Web20" AllowSorting="True" GridLines="None" AutoGenerateColumns="False" AutoGenerateEditColumn="True" AllowAutomaticUpdates="True">  
    2     <GroupPanel ID="GroupPanel" Style="width: 100%;">  
    3     </GroupPanel> 
    4     <ExportSettings> 
    5         <Pdf FontType="Subset" PaperSize="Letter" /> 
    6         <Excel Format="Html" /> 
    7     </ExportSettings> 
    8     <MasterTableView CommandItemDisplay="None" CurrentResetPageIndexAction="SetPageIndexToFirst" DataKeyNames="JobId" 
    9          Dir="LTR" Frame="Border" TableLayout="Auto" AllowAutomaticUpdates="True" EditMode="EditForms" Name="JobRow">  
    10         <EditFormSettings> 
    11             <EditColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType">  
    12             </EditColumn> 
    13         </EditFormSettings> 
    14         <ExpandCollapseColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType" 
    15             Resizable="False">  
    16             <HeaderStyle Width="20px" /> 
    17         </ExpandCollapseColumn> 
    18         <RowIndicatorColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType" 
    19             Visible="False">  
    20             <HeaderStyle Width="20px" /> 
    21         </RowIndicatorColumn> 
    22         <Columns> 
    23             <telerik:GridEditCommandColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType" 
    24                 UniqueName="AutoGeneratedEditColumn">  
    25                 <HeaderStyle Width="30px" /> 
    26             </telerik:GridEditCommandColumn> 
    27             <telerik:GridBoundColumn CurrentFilterFunction="NoFilter" DataField="OrderNumber" 
    28                 FilterListOptions="VaryByDataType" ForceExtractValue="None" HeaderText="Order Number" 
    29                 ReadOnly="True" UniqueName="OrderNumber">  
    30             </telerik:GridBoundColumn> 
    31             <telerik:GridBoundColumn CurrentFilterFunction="NoFilter" DataField="AccountName" 
    32                 FilterListOptions="VaryByDataType" ForceExtractValue="None" HeaderText="Account" 
    33                 ReadOnly="True" UniqueName="Account Name">  
    34             </telerik:GridBoundColumn> 
    35             <telerik:GridBoundColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType" 
    36                 ForceExtractValue="None" HeaderText="Address" SortExpression="Address" UniqueName="column" DataField="Address" ReadOnly="True">  
    37             </telerik:GridBoundColumn> 
    38             <telerik:GridBoundColumn CurrentFilterFunction="NoFilter" DataField="Suburb" FilterListOptions="VaryByDataType" 
    39                 ForceExtractValue="None" HeaderText="Suburb" ReadOnly="True" UniqueName="Suburb">  
    40             </telerik:GridBoundColumn> 
    41             <telerik:GridCheckBoxColumn CurrentFilterFunction="NoFilter" DataField="Vacant" FilterListOptions="VaryByDataType" 
    42                 ForceExtractValue="None" HeaderText="Vacant" SortExpression="Vacant" UniqueName="Vacant">  
    43                 </telerik:GridCheckBoxColumn> 
    44                         <telerik:GridCheckBoxColumn CurrentFilterFunction="NoFilter" DataField="Recall" FilterListOptions="VaryByDataType" 
    45                 ForceExtractValue="None" HeaderText="Recall" SortExpression="Recall" UniqueName="Recall">  
    46                 </telerik:GridCheckBoxColumn> 
    47                   <telerik:GridCheckBoxColumn CurrentFilterFunction="NoFilter" DataField="Confirmed" FilterListOptions="VaryByDataType" 
    48                 ForceExtractValue="None" HeaderText="Confirmed" SortExpression="Confirmed" UniqueName="Confirmed">  
    49                 </telerik:GridCheckBoxColumn> 
    50             <telerik:GridDateTimeColumn ReadOnly="True" CurrentFilterFunction="NoFilter" DataField="DueDateTime" FilterListOptions="VaryByDataType" 
    51                 ForceExtractValue="None" HeaderText="Due Date" SortExpression="DueDateTime" UniqueName="DueDateTime" DataType="System.DateTime"  DataFormatString="{0:d}">  
    52                 </telerik:GridDateTimeColumn> 
    53         </Columns> 
    54         <DetailTables> 
    55             <telerik:GridTableView runat="server" CommandItemDisplay="None" 
    56                 CurrentResetPageIndexAction="SetPageIndexToFirst" DataKeyNames="JobId,JobCodeId" DataSourceID="JobCodesSource" 
    57                 Dir="LTR" Frame="Border" TableLayout="Auto" HierarchyDefaultExpanded="false">  
    58                 <EditFormSettings> 
    59                     <EditColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType">  
    60                     </EditColumn> 
    61                 </EditFormSettings> 
    62                 <ParentTableRelation> 
    63                     <telerik:GridRelationFields DetailKeyField="JobId" MasterKeyField="JobId" /> 
    64                 </ParentTableRelation> 
    65                 <ExpandCollapseColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType" 
    66                     Resizable="False">  
    67                     <HeaderStyle Width="20px" /> 
    68                 </ExpandCollapseColumn> 
    69                 <RowIndicatorColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType" 
    70                     Visible="False">  
    71                     <HeaderStyle Width="20px" /> 
    72                 </RowIndicatorColumn> 
    73                 <Columns> 
    74                 <telerik:GridDropDownColumn DataField="CodeId" DataSourceID="CodeSource" ListTextField="CodeName"   
    75                             ListValueField="CodeId" HeaderText="Code" UniqueName="CodeId" CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType" ForceExtractValue="None">  
    76                      </telerik:GridDropDownColumn> 
    77  
    78                    <telerik:GridNumericColumn CurrentFilterFunction="NoFilter" DataField="QuantityRequired" 
    79                         DataType="System.Decimal" FilterListOptions="VaryByDataType" ForceExtractValue="None" 
    80                         HeaderText="QuantityRequired" SortExpression="QuantityRequired" UniqueName="QuantityRequired" NumericType="Number"</telerik:GridNumericColumn> 
    81                       
    82                     <telerik:GridNumericColumn CurrentFilterFunction="NoFilter" DataField="QuantityCompleted" 
    83                         DataType="System.Decimal" FilterListOptions="VaryByDataType" ForceExtractValue="None" 
    84                         HeaderText="QuantityCompleted" SortExpression="QuantityCompleted" UniqueName="QuantityCompleted" NumericType="Number">  
    85                         </telerik:GridNumericColumn>   
    86                     <telerik:GridBoundColumn CurrentFilterFunction="NoFilter" DataField="Comment" FilterListOptions="VaryByDataType" 
    87                         ForceExtractValue="None" HeaderText="Comment" SortExpression="Comment" UniqueName="Comment">  
    88                     </telerik:GridBoundColumn>           
    89                 </Columns> 
    90                 <DetailTables> 
    91                     <telerik:GridTableView runat="server" CommandItemDisplay="None" CurrentResetPageIndexAction="SetPageIndexToFirst" 
    92                         DataSourceID="JobScheduleSource" DataKeyNames="JobCodeId,ScheduleId" Dir="LTR" Frame="Border" TableLayout="Auto">  
    93                         <EditFormSettings> 
    94                             <EditColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType">  
    95                             </EditColumn> 
    96                         </EditFormSettings> 
    97                          <ParentTableRelation> 
    98                             <telerik:GridRelationFields DetailKeyField="JobCodeId" MasterKeyField="JobCodeId" /> 
    99                         </ParentTableRelation> 
    100                         <ExpandCollapseColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType" 
    101                             Resizable="False" Visible="False">  
    102                             <HeaderStyle Width="20px" /> 
    103                         </ExpandCollapseColumn> 
    104                         <RowIndicatorColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType" 
    105                             Visible="False">  
    106                             <HeaderStyle Width="20px" /> 
    107                         </RowIndicatorColumn> 
    108                         <Columns> 
    109                             <telerik:GridDateTimeColumn CurrentFilterFunction="NoFilter" DataField="ScheduleDateTime" 
    110                                 DataType="System.DateTime" FilterListOptions="VaryByDataType" ForceExtractValue="None" 
    111                                 HeaderText="Schedule Date/Time" UniqueName="ScheduleDateTime" PickerType="DateTimePicker">  
    112                             </telerik:GridDateTimeColumn> 
    113                             <telerik:GridDropDownColumn DataField="TechnicianId" DataSourceID="TechniciansSource" ListTextField="TechName"   
    114                             ListValueField="TechnicianId" HeaderText="Technician" UniqueName="TechnicianId" CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType" ForceExtractValue="None">  
    115                             </telerik:GridDropDownColumn> 
    116                             <telerik:GridBoundColumn CurrentFilterFunction="NoFilter" DataField="ScheduleNote" 
    117                                 FilterListOptions="VaryByDataType" ForceExtractValue="None" HeaderText="Notes" 
    118                                 MaxLength="200" UniqueName="ScheduleNote">  
    119                             </telerik:GridBoundColumn> 
    120                         </Columns> 
    121                     </telerik:GridTableView> 
    122                 </DetailTables> 
    123             </telerik:GridTableView> 
    124         </DetailTables> 
    125     </MasterTableView> 
    126 </telerik:RadGrid> 

    Please note that I have tried and confirmed that it all works if I just set the DataSourceId declartively in the RadGrid definition (i.e there is no problem with the sqldatasources).

    Also, the updates on the detail tables work fine (as they have the DataSourceId set declartively)

    Thanks,
    Fayez
  2. Giuseppe
    Admin
    Giuseppe avatar
    2363 posts

    Posted 17 Jan 2008 Link to this post

    Hello EmpowerIT,

    As noted here in order to insert/update/delete items automatically (without any extra coding) in Telerik RadGrid through a DataSourceControl API you have to relate a DataSourceControl to your grid instance through the DataSourceID attribute of the grid. You should not mix the declarative databinding approach with the advanced databinding capabilities provided by the NeedDataSource event. You can find more information on the distinct binding scenarios here under the section "Populating the control with data" >> "Understanding databinding".


    Sincerely yours,
    Manuel
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top