| 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 |
文档说明:
相关文档
返回首页 | 关于本站 | | 友情链接 | 广告服务 | 意见建议 | 访客留言 | 本站论坛
Copyright© 2001-2006 ProgramBBS.com All Rights Reserved 版权所有©编程论坛
Email: 吉ICP备05009985号
感谢长春订餐网友情支持