扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
SELECT [ID], [Name], [Address] from [Contacts] -- OverwriteChanges UPDATE [Contacts] SET [Name] = @Name, [Address] = @Address WHERE [ID] = @ID DELETE FROM [Contacts] WHERE [ID] = @ID -- CompareAllValues UPDATE [Contacts] SET [Name] = @Name, [Address] = @Address WHERE [ID] = @original_ID AND [Name] = @original_Name AND [Address] = @original_Address DELETE FROM [Contacts] WHERE [ID] = @original_ID AND [Name] = @original_Name AND [Address] = @original_Address |
<script runat="server"> Protected Sub SqlDataSource1_Updated(sender As Object, e As SqlDataSourceStatusEventArgs) If e.AffectedRows = 0 Then Response.Write("Row changed, update aborted<br />") End If End Sub Protected Sub SqlDataSource1_Deleted(sender As Object, e As SqlDataSourceStatusEventArgs) If e.AffectedRows = 0 Then Response.Write("Row changed, delete aborted<br />") End If End Sub </script> |
<asp:GridView ……> <Columns> <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" /> <asp:TemplateField HeaderText="ContactID" InsertVisible="False" SortExpression="ContactID"> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# Bind("ContactID") %>'></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:Label ID="Label3" runat="server" Text='<%# Eval("ContactID") %>'></asp:Label> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="ContactName" SortExpression="ContactName"> <ItemTemplate> <asp:Label ID="Label2" runat="server" Text='<%# Bind("ContactName") %>'></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("ContactName") %>'></asp:TextBox> </EditItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> |
你可以温和地处理冲突检测错误,可以通过提示用户下层数据被改变了,向用户显示改变过的值, 让用户选择提交或放弃自己的操作。下面的例子演示处理冲突检测的一种可行方法。请注意,DetailsView的RowUpdated事件参数传递了可用于检测用户输入的值的字典。你还可以设置这个事件参数的KeepInEditMode属性,使用户在决定如何处理冲突期间,DetailsView处于编辑模式。这个例子所试验方法与上面一个例子类似,同时打开两个窗口来创建冲突更新。
Protected Sub DetailsView1_ItemUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewUpdatedEventArgs) If e.AffectedRows = 0 Then ' 使DetailsView处于编辑模式并与数据库同步 e.KeepInEditMode = True DetailsView1.DataBind() ' 用用户输入的值重新填充DetailsView Dim t As TextBox t = DetailsView1.Rows(1).Cells(1).Controls(0) t.Text = e.NewValues("OrderDate") t = DetailsView1.Rows(2).Cells(1).Controls(0) t.Text = e.NewValues("ShipCountry") ErrorPanel.Visible = True Else ErrorPanel.Visible = False End If End Sub Protected Sub DetailsView1_ModeChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewModeEventArgs) If e.CancelingEdit = True AndAlso ErrorPanel.Visible = True Then ErrorPanel.Visible = False End If End Sub |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者