Hi All,
I have a nice working datagrid with a checkbox for each row. I also set the value of the checkbox depending on the data.
But I also want to allow the user to check/uncheck a box and have it post back that value (update) the database.
I bind the checkbox with this code:
Sub ComputeSumAndBindAccept(ByVal sender As Object, ByVal e As DataGridItemEventArgs)
'First, make sure we are dealing with an Item or AlternatingItem
If e.Item.ItemType = ListItemType.Item Or _
e.Item.ItemType = ListItemType.AlternatingItem Then
'Snip out the ViewCount
Dim chkB As CheckBox = New CheckBox
chkB = CType(e.Item.FindControl("AcceptCheck"), CheckBox)
If e.Item.DataItem("userwants") = "Y" Then
chkB.Checked = True
Dim viewCount As Integer = Convert.ToInt32(DataBinder.Eval(e.Item.DataItem, "Bid"))
viewCountSum += viewCount
Else
chkB.Checked = False
End If
ElseIf e.Item.ItemType = ListItemType.Footer Then
e.Item.Cells(3).Text = "Total: "
e.Item.Cells(3).HorizontalAlign = HorizontalAlign.Right
e.Item.Cells(4).Text = "$" & String.Format("{0:#,###}", viewCountSum)
e.Item.Cells(4).Font.Bold = True
e.Item.Cells(4).ForeColor = Color.Red
End If
End Sub
OK, so now I want to convert the checkbox value from 0,1 to Y/N and write it back to the db.
The question is should I use client side Javascript or have the checkbox autopostback and update the db that way?
First, I cannot seem to trap the checkbox event on the codebehind page.
Any help would be appreicated. Thanks.
I have a nice working datagrid with a checkbox for each row. I also set the value of the checkbox depending on the data.
But I also want to allow the user to check/uncheck a box and have it post back that value (update) the database.
I bind the checkbox with this code:
Sub ComputeSumAndBindAccept(ByVal sender As Object, ByVal e As DataGridItemEventArgs)
'First, make sure we are dealing with an Item or AlternatingItem
If e.Item.ItemType = ListItemType.Item Or _
e.Item.ItemType = ListItemType.AlternatingItem Then
'Snip out the ViewCount
Dim chkB As CheckBox = New CheckBox
chkB = CType(e.Item.FindControl("AcceptCheck"), CheckBox)
If e.Item.DataItem("userwants") = "Y" Then
chkB.Checked = True
Dim viewCount As Integer = Convert.ToInt32(DataBinder.Eval(e.Item.DataItem, "Bid"))
viewCountSum += viewCount
Else
chkB.Checked = False
End If
ElseIf e.Item.ItemType = ListItemType.Footer Then
e.Item.Cells(3).Text = "Total: "
e.Item.Cells(3).HorizontalAlign = HorizontalAlign.Right
e.Item.Cells(4).Text = "$" & String.Format("{0:#,###}", viewCountSum)
e.Item.Cells(4).Font.Bold = True
e.Item.Cells(4).ForeColor = Color.Red
End If
End Sub
OK, so now I want to convert the checkbox value from 0,1 to Y/N and write it back to the db.
The question is should I use client side Javascript or have the checkbox autopostback and update the db that way?
First, I cannot seem to trap the checkbox event on the codebehind page.
Any help would be appreicated. Thanks.