Hey All,
I have an app that shows users query results in a datagrid
bound to a dataset. The users indicate which rows they want
to see further details on by checking (or not) a checkbox on
each row. I save their choices to a db table when they click
a 'save' link, w/the below code. This works fine for
adding newly checked codes to the user's session, but now I
need the app to also *remove* codes that the user un-checks,
which that code doesn't do.
Now I could just blindly send a DELETE operation to the db
for every row that *isn't* checked, but I'd like to avoid
that traffic if it's possible. So as I loop through my
rows, when I find a row whose checkbox isn't checked, I
want to know whether it used to be checked--whether was
checked when I originally sent it down to the client. I've
got viewstate enabled on the grid, so I'm thinking it
should be possible, I just don't know how.
My naïve hope was that each DataGridItem would have
something in its .DataItem property that I could cast to a
DataRow, and get at the previous value that way. But no
dice--.DataItem is Nothing in every case.
(In case it matters, the checkbox column is an
<asp:TemplateColumn> that contains an
<asp:CheckBox> whose checked property is bound to the
appropriate datacolumn. All my other columns are
<asp:BoundColumns>.)
Can anybody throw me a clue on this?
Thanks!
-Roy
Private Sub SaveCodes(ByVal dg As DataGrid _
, ByVal chkname As String _
, ByVal lbl As Label _
, ByVal CodeType As CodeTypes)
Dim chk As CheckBox
Dim codes As New ArrayList
For Each i As DataGridItem In dg.Items
chk = CType(i.FindControl(chkname), CheckBox)
If chk.Checked Then
codes.Add(Integer.Parse(CType(i.Controls(1),
TableCell).Text))
Else
' How do I find out the previous value of
'selected'? so I can process de-selections?
' i.DataItem is Nothing!
End If
Next
If codes.Count > 0 Then
Try
If Globals.scnn.State <> ConnectionState.Open
Then Globals.scnn.Open()
For Each code As Integer In codes
InsertCode(code, CodeType,
Me.User.Identity.Name, Session.SessionID)
Next
Finally
If Globals.scnn.State = ConnectionState.Open Then
Globals.scnn.Close()
End Try
Me.lbReviewCodes.Enabled = True
End If
With lbl
.Text = "Saved " &
codes.Count.ToString & " codes."
.Visible = True
End With
End Sub
===================================
This list is hosted by DevelopMentor® http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com
|