By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,851 Members | 1,121 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,851 IT Pros & Developers. It's quick & easy.

C#-WEB: DetailsView, ModeChanging, and checking for data changes

P: 2
I've been working on concurrency checking for an application I'm building, and a minor part of it has me slightly stumped.


I've got a DetailsView that populates from an ObjectDataSource, using business objects with optimistic concurrency checking built in in my Save() method (against a timestamp column). This can be proven to work perfectly in the following scenario:

- Start app, go to the DetailsView page (defaults to readonly), open a new window

- In one window, go to Update mode

- In the other window, go to Update mode, make a change, click Update

- In the first window, make a change and click update

This will cause my code to generate a DBConcurrencyException. All well and good. However, take the following scenario:

- Start app, go to DetailsView page, open a new window

- In one window, go to update mode, make a change, click update

- In the other window, go to Update mode

You will ender Update mode with the changed data. Now, technically, this works, however when this happens (data changed between the time it was opened for reading and the time it was opened for writing) I want to alert the user.

My first thought is to add something to the ModeChanged event for the DetailsView, but what to add to do the checking I am unsure about. Does anyone have any advice here?

Thanks!



Here's the relevant code.


EventDetails.aspx

1 <%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="EventDetails.aspx.cs" Inherits="EventDetails" Title="Untitled Page" %>
2 <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
3 <asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Style="position: relative"
4 Width="125px" OnModeChanging="DetailsView1_ModeChanging" AutoGenerateRows="False" DataSourceID="ObjectDataSource1" DataKeyNames="ID,Timestamp">
5 <Fields>
6 <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
7 <asp:BoundField DataField="StartDateTime" HeaderText="StartDateTime" SortExpression="StartDateTime" />
8 <asp:BoundField DataField="EndDateTime" HeaderText="EndDateTime" SortExpression="EndDateTime" />
9 <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
10 <asp:CommandField ShowEditButton="True" />
11 </Fields>
12
13 </asp:DetailsView>
14 <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" DataObjectTypeName="BSC.PID.BO.CalendarEvent"
15 SelectMethod="GetEvent" TypeName="BSC.PID.BLL.CalendarEventManager" UpdateMethod="Save">
16 <SelectParameters>
17 <asp:QueryStringParameter Name="id" QueryStringField="id" Type="Int32" />
18 </SelectParameters>
19 </asp:ObjectDataSource>
20 </asp:Content>
21
22



EventDetails.aspx.cs



1 using System;
2 using System.Data;
3 using System.Configuration;
4 using System.Collections;
5 using System.Web;
6 using System.Web.Security;
7 using System.Web.UI;
8 using System.Web.UI.WebControls;
9 using System.Web.UI.WebControls.WebParts;
10 using System.Web.UI.HtmlControls;
11
12 using BSC.PID.BO;
13 using BSC.PID.BLL;
14
15 public partial class EventDetails : System.Web.UI.Page
16 {
17 protected void Page_Load(object sender, EventArgs e)
18 {
19
20 }
21 protected void DetailsView1_ModeChanging(object sender, DetailsViewModeEventArgs e)
22 {
23
24 }
25 }
26
Dec 18 '07 #1
Share this Question
Share on Google+
1 Reply


P: 2
Bump for the new day. Anyone?
Dec 19 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.