C rowupdating datakey

Bạn click vào Grid View properties lên chọn qua tab Events (Dấu sấm sét trong hình).

Chọn vào các sự kiện như trong hình và Enter (Nhớ là có hậu tố ing không chọn sự kiện hâu tố ed).

Bạn bấm vào Edit sẽ chạy sự kiện Row Editing đồng thời sẽ hiển thị hai nút, Update và Cancel nếu bấm Update thì chạy sự kiện Row Updating nếu bấm Cancel Thì chạy sự kiện Row Canceling Edit.

c rowupdating datakey-33

Muốn là được điều này thì Grid View bạn phải có field nào đó là Data Key để dựa vào đó để xét.Ở đây mình vẫn làm típ vi dụ ở bài Thêm xóa sửa trong ASP.Shame I haven't written code to use this event though – the code I am working with has come from a Data Grid in .net1.1 where that event didn't even exist if I remember right.I'm not sure if a race condition exists there or not (it's what all the examples out of MS say to use – that doesn't mean they are correct). Given data that is alpha sorted: user A loads the page with the B inserts a new row that would be sorted towards the A clicks to edit a row at index 5user A sets the Edit Index to 5, and then rebinds the grid. I'd need to run a test to confirm that is the case however.When clicking edit store this Data Key somewhere (session, querystring.. then the On Row Data Bound event, check if the current row's data key matches the one you have saved – if so, set the Edit Index to be that of the current row. I have come up with a really bad working solution – please keep in mind i do persist my viewstate to the server file system and have compression and all sorts of fun working to speed up the load and reduce the network costs, so not soo bad...

Then in the Grid Data Bound event, you have to call Data Bind() again... I have: Public Property Stored Note DT() As Data Table Get Return View State("Stored Note DT") End Get Set(By Val value As Data Table) View State("Stored Note DT") = value End Set End Property Private Sub Bind Grid(byval Use Stored DT as boolean) Dim DT As New Data Table If Use Stored DT = True And Not Stored Note DT Is Nothing Then DT = Stored Note DT Else DT = 'Do database call and get new data. I'm trying to think of away around this, because I have a grid that get hammered and I need to make sure a user editing a grid is editing the correct record. I'm going to have to do a coding work around rather than relying on the Grid View routines. til quando estamos utilizando um Grid View para editar um registro de banco de dados.1- Row Canceling Edit: Este evento disparado quando cancelamos a atualizao de um registro, o que significa que usamos isso quando estamos em modo de edio de um Grid View e queremos retornar o Grid View de volta ao modo de visualizao, sem qualquer atualizao.O evento Row Data Bound disparado sempre que uma linha adicionada ao Grid View, isto ocorre tanto quando o Grid View criado pela primeira vez e sempre que a pgina recarregada.After the rebind the intended row to be edited is now at index of 6, so the wrong row is selected. Perhaps internally it uses a different system for keeping track of which rows which would negate the above.