"Lock" Gridview row
-
Hi, I am writing a web app in ASP.Net 2.0 and server side C#. what i am trying to achieve is this: multiple users work of a gridview and user A selects a row in the gridview to work with, now when user B selects the same row while user A is still busy with that row, user B must be notified that that specific row is in use by another user. A notify message or a row lock or anything to prevent user B from working with the same record as User A. Does anyone have any idea how i could work around this one? :doh: Thanks alot Kind Regards GermanD
-
Hi, I am writing a web app in ASP.Net 2.0 and server side C#. what i am trying to achieve is this: multiple users work of a gridview and user A selects a row in the gridview to work with, now when user B selects the same row while user A is still busy with that row, user B must be notified that that specific row is in use by another user. A notify message or a row lock or anything to prevent user B from working with the same record as User A. Does anyone have any idea how i could work around this one? :doh: Thanks alot Kind Regards GermanD
Yeah, here is what I do. First of all, here are two sql procs
create proc [dbo].[uspLockItem] (@workItemId int, @User varchar(50)) as update dbo.workItems set lockedBy = @User, lockedTime = getdate() where workItemId = @workItemId create proc [dbo].[uspUnLockItems] (@User varchar(50)) as update dbo.workItems set lockedBy = null, lockedTime = null where lockedBy is not null and ( lockedBy = @User or datediff(minute, lockedTime, getdate()) > 20 )
Lock the first record when the user loads the page to work on it. Unlock right before you get data for your grid. On item databound method or whereever you bind your gridLinkButton lb = (LinkButton)e.Item.FindControl("lbEdit"); if (drv["lockedBy"] != DBNull.Value) { lb.Enabled = false; lb.ToolTip = "Policy locked by " + drv["lockedBy"].ToString(); }