更新Telerik Rad网格?

时间:2019-03-13 18:43:13

标签: c# linq telerik-grid

因此,我有一个自动生成的RadGrid,它是通过LINQ填充的。更新命令不执行任何操作。取消有效,但是当我单击“编辑”时,将打开编辑列,但更改不会“生效”。我究竟做错了什么?同一页面上的其他RadGrid似乎工作正常。

这是网格:

  <telerik:RadGrid ID="DailyHoursGrid" runat="server" 
                    AutoGenerateEditColumn="True" CellSpacing="0" DataSourceID="LinqDataSource3" 
                    GridLines="None">                       
                    <ClientSettings>
                        <Selecting CellSelectionMode="None" />
                    </ClientSettings>
                    <MasterTableView AutoGenerateColumns="False" DataSourceID="LinqDataSource3">
                        <CommandItemSettings ExportToPdfText="Export to PDF" />
                        <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column" 
                            Visible="True">
                            <HeaderStyle Width="20px" />
                        </RowIndicatorColumn>
                        <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" 
                            Visible="True">
                            <HeaderStyle Width="20px" />
                        </ExpandCollapseColumn>
                        <Columns>
                            <telerik:GridBoundColumn DataField="Employee" DataType="System.Int32" 
                                FilterControlAltText="Filter Employee column" HeaderText="Employee" 
                                ReadOnly="True" SortExpression="Employee" UniqueName="Employee">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="EventType" 
                                FilterControlAltText="Filter EventType column" HeaderText="EventType" 
                                ReadOnly="True" SortExpression="EventType" UniqueName="EventType">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Time" DataType="System.DateTime" 
                                FilterControlAltText="Filter Time column" HeaderText="Time" ReadOnly="False" 
                                SortExpression="Time" UniqueName="Time">
                            </telerik:GridBoundColumn>
                        </Columns>
                        <EditFormSettings>
                            <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                            </EditColumn>
                        </EditFormSettings>
                    </MasterTableView>
                    <FilterMenu EnableImageSprites="False">
                    </FilterMenu>

                </telerik:RadGrid>

还有LINQ:

  <asp:LinqDataSource ID="LinqDataSource3" runat="server" 
                    ContextTypeName="TimeClock.TimeClockEntities2" EntityTypeName="" OrderBy="Time" 
                    Select="new (Employee, EventType, Time)" TableName="Events" 


                    Where="Time &gt;= @Time &amp;&amp; Time &lt;= @Time1 &amp;&amp; Employee == @Employee" 
                    EnableUpdate="True" EnableInsert="True">
                    <WhereParameters>
                        <asp:ControlParameter ControlID="StartDatePicker" DefaultValue="0:00" Name="Time" 
                            PropertyName="SelectedDate" Type="DateTime" />
                        <asp:ControlParameter ControlID="EndDatePicker" DefaultValue="0:00" Name="Time1" 
                            PropertyName="SelectedDate" Type="DateTime" />
                        <asp:ControlParameter ControlID="HourlyReportEmployeeCombo" DefaultValue="0" 
                            Name="Employee" PropertyName="SelectedValue" Type="Int32" />
                    </WhereParameters>
                </asp:LinqDataSource>

1 个答案:

答案 0 :(得分:0)

RadGrid提供两种CRUD操作:AutomaticManual

对于“自动”,可以分别针对它们自己的操作启用以下网格属性: AllowAutomaticUpdates, AllowAutomaticInserts, AllowAutomaticDeletes

另一个要求是LinqDataSource应该包含相应的参数,以允许网格识别将被传递到数据库的值:

<asp:LinqDataSource ID="LinqDataSource1" runat="server">
  <UpdateParameters>
    ...
  </UpdateParameters>
</asp:LinqDataSource>

您可以在本文的第一个代码段中找到有用的类似示例,其中包含SqlDataSource: Automatic DataSource Operations

对于更多控制,复杂情况或StoredProcedures,最好使用手动CRUD操作,以利用网格提供的Update // Insert- / DeleteCommand或ItemCommand事件处理程序。