更新Telerik Rad Grid?

问题描述 投票:0回答:1

所以,我有一个自动生成的RadGrid,通过LINQ填充。 Update命令不执行任何操作。取消有效但当我单击编辑时,编辑列会打开,但更改不会“取走”。我究竟做错了什么?同一页面上的其他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>
c# linq telerik-grid
1个回答
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事件处理程序。

© www.soinside.com 2019 - 2024. All rights reserved.