LinqDataSource.EnableUpdate 属性
定义
获取或设置一个值,该值指示是否可以通过 LinqDataSource 控件更新数据记录。Gets or sets a value that indicates whether data records can be updated through the LinqDataSource control.
public:
property bool EnableUpdate { bool get(); void set(bool value); };
public bool EnableUpdate { get; set; }
member this.EnableUpdate : bool with get, set
Public Property EnableUpdate As Boolean
属性值
如果启用了自动更新操作,则为 true;否则为 false。true if automatic update operations are enabled; otherwise, false. 默认值是 false。The default value is false.
实现
示例
下面的示例演示了一个 LinqDataSource EnableUpdate 设置为的控件 true 。The following example shows a LinqDataSource control that has EnableUpdate set to true. DetailsView控件显示数据,并创建一个按钮,该按钮允许用户更新数据记录。A DetailsView control displays the data and creates a button that lets users update a data record.
<asp:LinqDataSource
ContextTypeName="ExampleDataContext"
TableName="Products"
EnableUpdate="true"
EnableInsert="true"
EnableDelete="true"
ID="LinqDataSource1"
runat="server">
</asp:LinqDataSource>
<asp:DetailsView
DataKeyNames="ProductID"
AutoGenerateEditButton="true"
AutoGenerateDeleteButton="true"
AutoGenerateInsertButton="true"
AllowPaging="true"
DataSourceID="LinqDataSource1"
ID="GridView1"
runat="server">
</asp:DetailsView>
<asp:LinqDataSource
ContextTypeName="ExampleDataContext"
TableName="Products"
EnableUpdate="true"
EnableInsert="true"
EnableDelete="true"
ID="LinqDataSource1"
runat="server">
</asp:LinqDataSource>
<asp:DetailsView
DataKeyNames="ProductID"
AutoGenerateEditButton="true"
AutoGenerateDeleteButton="true"
AutoGenerateInsertButton="true"
AllowPaging="true"
DataSourceID="LinqDataSource1"
ID="GridView1"
runat="server">
</asp:DetailsView>
注解
EnableUpdate true 如果希望允许用户使用控件更新数据记录,请将属性设置为 LinqDataSource 。Set the EnableUpdate property to true when you want to enable users to update a data record by using the LinqDataSource control. 当 EnableUpdate 为时 true , LinqDataSource 控件使用 LINQ to SQL 自动创建用于更新数据的命令。When EnableUpdate is true, the LinqDataSource control uses LINQ to SQL to automatically create the command to update the data. 必须包含允许用户更新记录(如控件)的接口 DetailsView 。You must include an interface that lets users update a record, such as a DetailsView control.
LinqDataSource当 Select 设置属性或属性时,控件不支持自动更新操作 GroupBy 。The LinqDataSource control does not support automatic update operations when the Select property or the GroupBy property is set. 在这种情况下, LinqDataSource 如果尝试更新操作,控件将引发异常。In that case, the LinqDataSource control throws an exception if an update operation is tried.