Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checked Box in datagrid

Status
Not open for further replies.
Apr 3, 2005
32
US
I have the following code that is suppose to insert the following data when the user checked the checkbox in one of the column of the datagrid. However, I can't seem to get pass the
'If (Checkselector.Value = False And Checkselector.Checked) Then '
Is there a better way to verify if the checkbox is checked??
Any suggestion is greatly appreciated. Thank you


Private Sub Confirm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Confirm.Click
Dim dgItem As DataGridItem
Dim Checkselector As System.Web.UI.HtmlControls.HtmlInputCheckBox

For Each dgItem In dgActivity.Items
If (Checkselector.Value = False And Checkselector.Checked) Then
Dim transConn1 As SqlConnection
Dim transAdapt As SqlDataAdapter
transConn1 = New SqlConnection("data source=servername" & _
";persist security info=False;initial catalog=BUD")
transConn1.Open()
Dim insrtstring As String = "insert into CorrectionData (CreditAcctUnit, CreditAcct, CreditActivity, CreditCategory, Credit_Ind, CreditAmt, CreditUnit, CreditDescription, CreditReference, DebitAcctUnit, DebitAcct, DebitActivity, DebitCategory, Debit_Ind, DebitAmt, DebitUnit, DebitDescription, DebitReference, TransferUserID, PostingDate, Year, Period, InvoiceDate, TransType) values ('12001', '5003', '03010598', '1617', 'C', 12.50, 2, 'Payroll', '097653','12001', '5003', '03010598', '1617', 'C', 12.50, 2, 'Payroll', '097653','dhh', 8/15/2005, 2005, 8, 8/15/2005, 'RT')"
Dim transComm As New SqlCommand(insrtstring, transConn1)
transComm.ExecuteNonQuery()
transConn1.Close()
End If
Next
End Sub
 
If (Checkselector.Value = False And Checkselector.Checked) Then



why are u checking for the value? and why is it boolean?

try this:
Checkselector=ctype(dgItem.FindControl("Checkselector"),Checkbox)
If (Checkselector.Value = "False" And Checkselector.Checked) Then


Known is handfull, Unknown is worldfull
 
I'm not sure what I should do for checking whether the checkbox is checked, so I use boolean to verify the state. But if there is a better technique, please let me know.
In addition, I've tried the following
Checkselector=ctype(dgItem.FindControl("Checkselector"),Checkbox)
If (Checkselector.Value = "False" And Checkselector.Checked) Then

However, it doesn't allow for me to do that because it is not part of the Web.UI.HTMLControl.HTMLInputCheckbox

So I've tried the following
Dim Checkselector As System.Web.UI.WebControls.CheckBox
For Each dgItem In dgActivity.Items
Checkselector = CType(dgItem.FindControl("Checkselector"), CheckBox)
If (Checkselector.Checked) Then

But when I run it, it said
"Object reference not set to an instance of an object."

I'm very new at this, so please bear with me.
Thank you,
 
>>Checkselector = CType(dgItem.FindControl("Checkselector"), CheckBox)


The Checkselector in the FindControl method is the name of the Checkbox control, what error u r recieving is beacuse the FindControl() method is not returning any values...

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top