更新 Telerik Rad 网格?

Updating Telerik Rad Grid?

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

这是网格:

  <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>

RadGrid 提供 2 种类型的 CRUD 操作:Automatic and Manual.

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

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

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

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

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