473,587 Members | 2,263 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

checkbox on gridview

Hi, I am using a gridview with a templatefield containing a checkbox.
I want to update the database with a 1 or 0 depending on if a checkbox
is checked or unchecked (then use the 1 or 0 later on another page)..i
have been google around and found this....

If e.Row.RowType = DataControlRowT ype.DataRow Then

Dim Chk As CheckBox = e.Row.FindContr ol("CheckBox1" )

just dont know what to do next...Any ideas?

Dec 12 '06 #1
9 5529

Well, how you do it depends on when you want to do the update. Basically you
need to indeed find the control in the row/column. When data is bound to the
grid, this event fires for each row bound to the control. The event args 'e'
is passed to the function and you can use this to check if the checkbox is
checked or not.

(Not tested but something like this)

'//e contains the Item which is the current row.
dim cb as checkbox

cb= Ctype(e.item(in dexColumnNumber ).controls(1),c heckbox)

if cb.selected = true then

'//do domething

end if

HTH
<mi********@yah oo.co.ukwrote in message
news:11******** *************@8 0g2000cwy.googl egroups.com...
Hi, I am using a gridview with a templatefield containing a checkbox.
I want to update the database with a 1 or 0 depending on if a checkbox
is checked or unchecked (then use the 1 or 0 later on another page)..i
have been google around and found this....

If e.Row.RowType = DataControlRowT ype.DataRow Then

Dim Chk As CheckBox = e.Row.FindContr ol("CheckBox1" )

just dont know what to do next...Any ideas?

Dec 12 '06 #2
Hi
I have expanded on what i had originally but still cant get it to
update DB...here is the new code i have....

Protected Sub GridView1_RowDa taBound(ByVal sender As Object, ByVal e As
System.Web.UI.W ebControls.Grid ViewRowEventArg s) Handles
GridView1.RowDa taBound

Dim MyConnection As OdbcConnection

MyConnection = New OdbcConnection( ) 'declare new connection
object

MyConnection.Co nnectionString = "" 'database connect string

MyConnection.Op en() 'open connection to database

Dim MyCommand As New OdbcCommand() 'declare new command object

MyCommand.Conne ction = MyConnection

If e.Row.RowType = DataControlRowT ype.DataRow Then

Dim Chk As CheckBox = e.Row.Cells(5). FindControl("sa ve")

If Chk.Checked = True Then
MyCommand.Comma ndText = "update support.support set
save = 1"

End If

If Chk.Checked = False Then
MyCommand.Comma ndText = "update support.support set
save = 0"

End If
MyCommand.Execu teNonQuery()

MyConnection.Cl ose()

MyCommand = Nothing

'MsgBox(Chk.Che cked)

End If

End Sub



Goofy wrote:
Well, how you do it depends on when you want to do the update. Basically you
need to indeed find the control in the row/column. When data is bound to the
grid, this event fires for each row bound to the control. The event args 'e'
is passed to the function and you can use this to check if the checkbox is
checked or not.

(Not tested but something like this)

'//e contains the Item which is the current row.
dim cb as checkbox

cb= Ctype(e.item(in dexColumnNumber ).controls(1),c heckbox)

if cb.selected = true then

'//do domething

end if

HTH
<mi********@yah oo.co.ukwrote in message
news:11******** *************@8 0g2000cwy.googl egroups.com...
Hi, I am using a gridview with a templatefield containing a checkbox.
I want to update the database with a 1 or 0 depending on if a checkbox
is checked or unchecked (then use the 1 or 0 later on another page)..i
have been google around and found this....

If e.Row.RowType = DataControlRowT ype.DataRow Then

Dim Chk As CheckBox = e.Row.FindContr ol("CheckBox1" )

just dont know what to do next...Any ideas?
Dec 12 '06 #3
breakpoint the line as shown below and see if you get an exception, if you
do look at the exception message and see what its telling you and go from
there.

Try

MyCommand.Execu teNonQuery() '// breakpoint it here
Catch ex as Exception

End Try


"mike7510uk " <mi********@yah oo.co.ukwrote in message
news:11******** **************@ 80g2000cwy.goog legroups.com...
Hi
I have expanded on what i had originally but still cant get it to
update DB...here is the new code i have....

Protected Sub GridView1_RowDa taBound(ByVal sender As Object, ByVal e As
System.Web.UI.W ebControls.Grid ViewRowEventArg s) Handles
GridView1.RowDa taBound

Dim MyConnection As OdbcConnection

MyConnection = New OdbcConnection( ) 'declare new connection
object

MyConnection.Co nnectionString = "" 'database connect string

MyConnection.Op en() 'open connection to database

Dim MyCommand As New OdbcCommand() 'declare new command object

MyCommand.Conne ction = MyConnection

If e.Row.RowType = DataControlRowT ype.DataRow Then

Dim Chk As CheckBox = e.Row.Cells(5). FindControl("sa ve")

If Chk.Checked = True Then
MyCommand.Comma ndText = "update support.support set
save = 1"

End If

If Chk.Checked = False Then
MyCommand.Comma ndText = "update support.support set
save = 0"

End If
MyCommand.Execu teNonQuery()

MyConnection.Cl ose()

MyCommand = Nothing

'MsgBox(Chk.Che cked)

End If

End Sub



Goofy wrote:
>Well, how you do it depends on when you want to do the update. Basically
you
need to indeed find the control in the row/column. When data is bound to
the
grid, this event fires for each row bound to the control. The event args
'e'
is passed to the function and you can use this to check if the checkbox
is
checked or not.

(Not tested but something like this)

'//e contains the Item which is the current row.
dim cb as checkbox

cb= Ctype(e.item(in dexColumnNumber ).controls(1),c heckbox)

if cb.selected = true then

'//do domething

end if

HTH
<mi********@ya hoo.co.ukwrote in message
news:11******* **************@ 80g2000cwy.goog legroups.com...
Hi, I am using a gridview with a templatefield containing a checkbox.
I want to update the database with a 1 or 0 depending on if a checkbox
is checked or unchecked (then use the 1 or 0 later on another page)..i
have been google around and found this....

If e.Row.RowType = DataControlRowT ype.DataRow Then

Dim Chk As CheckBox = e.Row.FindContr ol("CheckBox1" )

just dont know what to do next...Any ideas?

Dec 12 '06 #4
Tried that and nothing happened, it loaded page up ok and let me click
the checkboxes but no DB update
Goofy wrote:
breakpoint the line as shown below and see if you get an exception, if you
do look at the exception message and see what its telling you and go from
there.

Try

MyCommand.Execu teNonQuery() '// breakpoint it here
Catch ex as Exception

End Try


"mike7510uk " <mi********@yah oo.co.ukwrote in message
news:11******** **************@ 80g2000cwy.goog legroups.com...
Hi
I have expanded on what i had originally but still cant get it to
update DB...here is the new code i have....

Protected Sub GridView1_RowDa taBound(ByVal sender As Object, ByVal e As
System.Web.UI.W ebControls.Grid ViewRowEventArg s) Handles
GridView1.RowDa taBound

Dim MyConnection As OdbcConnection

MyConnection = New OdbcConnection( ) 'declare new connection
object

MyConnection.Co nnectionString = "" 'database connect string

MyConnection.Op en() 'open connection to database

Dim MyCommand As New OdbcCommand() 'declare new command object

MyCommand.Conne ction = MyConnection

If e.Row.RowType = DataControlRowT ype.DataRow Then

Dim Chk As CheckBox = e.Row.Cells(5). FindControl("sa ve")

If Chk.Checked = True Then
MyCommand.Comma ndText = "update support.support set
save = 1"

End If

If Chk.Checked = False Then
MyCommand.Comma ndText = "update support.support set
save = 0"

End If
MyCommand.Execu teNonQuery()

MyConnection.Cl ose()

MyCommand = Nothing

'MsgBox(Chk.Che cked)

End If

End Sub



Goofy wrote:
Well, how you do it depends on when you want to do the update. Basically
you
need to indeed find the control in the row/column. When data is bound to
the
grid, this event fires for each row bound to the control. The event args
'e'
is passed to the function and you can use this to check if the checkbox
is
checked or not.

(Not tested but something like this)

'//e contains the Item which is the current row.
dim cb as checkbox

cb= Ctype(e.item(in dexColumnNumber ).controls(1),c heckbox)

if cb.selected = true then

'//do domething

end if

HTH
<mi********@yah oo.co.ukwrote in message
news:11******** *************@8 0g2000cwy.googl egroups.com...
Hi, I am using a gridview with a templatefield containing a checkbox.
I want to update the database with a 1 or 0 depending on if a checkbox
is checked or unchecked (then use the 1 or 0 later on another page)..i
have been google around and found this....

If e.Row.RowType = DataControlRowT ype.DataRow Then

Dim Chk As CheckBox = e.Row.FindContr ol("CheckBox1" )

just dont know what to do next...Any ideas?
Dec 12 '06 #5
am i even running the code in the correct sub?
mike7510uk wrote:
Tried that and nothing happened, it loaded page up ok and let me click
the checkboxes but no DB update
Goofy wrote:
breakpoint the line as shown below and see if you get an exception, if you
do look at the exception message and see what its telling you and go from
there.

Try

MyCommand.Execu teNonQuery() '// breakpoint it here
Catch ex as Exception

End Try


"mike7510uk " <mi********@yah oo.co.ukwrote in message
news:11******** **************@ 80g2000cwy.goog legroups.com...
Hi
I have expanded on what i had originally but still cant get it to
update DB...here is the new code i have....
>
Protected Sub GridView1_RowDa taBound(ByVal sender As Object, ByVal e As
System.Web.UI.W ebControls.Grid ViewRowEventArg s) Handles
GridView1.RowDa taBound
>
>
>
Dim MyConnection As OdbcConnection
>
MyConnection = New OdbcConnection( ) 'declare new connection
object
>
MyConnection.Co nnectionString = "" 'database connect string
>
MyConnection.Op en() 'open connection to database
>
Dim MyCommand As New OdbcCommand() 'declare new command object
>
MyCommand.Conne ction = MyConnection
>
>
>
If e.Row.RowType = DataControlRowT ype.DataRow Then
>
Dim Chk As CheckBox = e.Row.Cells(5). FindControl("sa ve")
>
>
>
If Chk.Checked = True Then
MyCommand.Comma ndText = "update support.support set
save = 1"
>
>
>
End If
>
If Chk.Checked = False Then
MyCommand.Comma ndText = "update support.support set
save = 0"
>
>
>
End If
>
>
MyCommand.Execu teNonQuery()
>
MyConnection.Cl ose()
>
MyCommand = Nothing
>
>
>
'MsgBox(Chk.Che cked)
>
>
>
End If
>
End Sub
>
>
>
>
>
>
>
>
>
>
>
Goofy wrote:
>Well, how you do it depends on when you want to do the update. Basically
>you
>need to indeed find the control in the row/column. When data is bound to
>the
>grid, this event fires for each row bound to the control. The event args
>'e'
>is passed to the function and you can use this to check if the checkbox
>is
>checked or not.
>>
>(Not tested but something like this)
>>
>'//e contains the Item which is the current row.
>dim cb as checkbox
>>
>cb= Ctype(e.item(in dexColumnNumber ).controls(1),c heckbox)
>>
>if cb.selected = true then
>>
>'//do domething
>>
>end if
>>
>HTH
>>
>>
><mi********@ya hoo.co.ukwrote in message
>news:11******* **************@ 80g2000cwy.goog legroups.com...
Hi, I am using a gridview with a templatefield containing a checkbox.
I want to update the database with a 1 or 0 depending on if a checkbox
is checked or unchecked (then use the 1 or 0 later on another page)..i
have been google around and found this....
>
If e.Row.RowType = DataControlRowT ype.DataRow Then
>
Dim Chk As CheckBox = e.Row.FindContr ol("CheckBox1" )
>
just dont know what to do next...Any ideas?
>
>
Dec 12 '06 #6
with the code you posted earlier ('//e contains the Item which is the
current row.
dim cb as checkbox
cb= Ctype(e.item(in dexColumnNumber ).controls(1),c heckbox)
if cb.selected = true then
'//do domething
end if )

i get the error saying "item is not a member of system.web etc etc

mike7510uk wrote:
am i even running the code in the correct sub?
mike7510uk wrote:
Tried that and nothing happened, it loaded page up ok and let me click
the checkboxes but no DB update
Goofy wrote:
breakpoint the line as shown below and see if you get an exception, if you
do look at the exception message and see what its telling you and go from
there.
>
Try
>
MyCommand.Execu teNonQuery() '// breakpoint it here
>
>
Catch ex as Exception
>
>
>
End Try
>
>
>
>
"mike7510uk " <mi********@yah oo.co.ukwrote in message
news:11******** **************@ 80g2000cwy.goog legroups.com...
Hi
I have expanded on what i had originally but still cant get it to
update DB...here is the new code i have....

Protected Sub GridView1_RowDa taBound(ByVal sender As Object, ByVal e As
System.Web.UI.W ebControls.Grid ViewRowEventArg s) Handles
GridView1.RowDa taBound



Dim MyConnection As OdbcConnection

MyConnection = New OdbcConnection( ) 'declare new connection
object

MyConnection.Co nnectionString = "" 'database connect string

MyConnection.Op en() 'open connection to database

Dim MyCommand As New OdbcCommand() 'declare new command object

MyCommand.Conne ction = MyConnection



If e.Row.RowType = DataControlRowT ype.DataRow Then

Dim Chk As CheckBox = e.Row.Cells(5). FindControl("sa ve")



If Chk.Checked = True Then
MyCommand.Comma ndText = "update support.support set
save = 1"



End If

If Chk.Checked = False Then
MyCommand.Comma ndText = "update support.support set
save = 0"



End If


MyCommand.Execu teNonQuery()

MyConnection.Cl ose()

MyCommand = Nothing



'MsgBox(Chk.Che cked)



End If

End Sub











Goofy wrote:
Well, how you do it depends on when you want to do the update. Basically
you
need to indeed find the control in the row/column. When data is bound to
the
grid, this event fires for each row bound to the control. The event args
'e'
is passed to the function and you can use this to check if the checkbox
is
checked or not.
>
(Not tested but something like this)
>
'//e contains the Item which is the current row.
dim cb as checkbox
>
cb= Ctype(e.item(in dexColumnNumber ).controls(1),c heckbox)
>
if cb.selected = true then
>
'//do domething
>
end if
>
HTH
>
>
<mi********@yah oo.co.ukwrote in message
news:11******** *************@8 0g2000cwy.googl egroups.com...
Hi, I am using a gridview with a templatefield containing a checkbox.
I want to update the database with a 1 or 0 depending on if a checkbox
is checked or unchecked (then use the 1 or 0 later on another page)..i
have been google around and found this....

If e.Row.RowType = DataControlRowT ype.DataRow Then

Dim Chk As CheckBox = e.Row.FindContr ol("CheckBox1" )

just dont know what to do next...Any ideas?
Dec 12 '06 #7
mike7510uk wrote:
Tried that and nothing happened, it loaded page up ok and let me click
the checkboxes but no DB update
Goofy wrote:
>breakpoint the line as shown below and see if you get an exception, if you
do look at the exception message and see what its telling you and go from
there.

Try

MyCommand.Execu teNonQuery() '// breakpoint it here
Catch ex as Exception

End Try


"mike7510uk " <mi********@yah oo.co.ukwrote in message
news:11******* *************** @80g2000cwy.goo glegroups.com.. .
>>Hi
I have expanded on what i had originally but still cant get it to
update DB...here is the new code i have....

Protected Sub GridView1_RowDa taBound(ByVal sender As Object, ByVal e As
System.Web.UI .WebControls.Gr idViewRowEventA rgs) Handles
GridView1.Row DataBound

Dim MyConnection As OdbcConnection

MyConnection = New OdbcConnection( ) 'declare new connection
object

MyConnection.Co nnectionString = "" 'database connect string

MyConnection.Op en() 'open connection to database

Dim MyCommand As New OdbcCommand() 'declare new command object

MyCommand.Conne ction = MyConnection

If e.Row.RowType = DataControlRowT ype.DataRow Then

Dim Chk As CheckBox = e.Row.Cells(5). FindControl("sa ve")

If Chk.Checked = True Then
MyCommand.Comma ndText = "update support.support set
save = 1"

End If

If Chk.Checked = False Then
MyCommand.Comma ndText = "update support.support set
save = 0"

End If
MyCommand.Execu teNonQuery()

MyConnection.Cl ose()

MyCommand = Nothing

'MsgBox(Chk.Che cked)

End If

End Sub



Goofy wrote:
Well, how you do it depends on when you want to do the update. Basically
you
need to indeed find the control in the row/column. When data is bound to
the
grid, this event fires for each row bound to the control. The event args
'e'
is passed to the function and you can use this to check if the checkbox
is
checked or not.

(Not tested but something like this)

'//e contains the Item which is the current row.
dim cb as checkbox

cb= Ctype(e.item(in dexColumnNumber ).controls(1),c heckbox)

if cb.selected = true then

'//do domething

end if

HTH
<mi********@ yahoo.co.ukwrot e in message
news:11***** *************** *@80g2000cwy.go oglegroups.com. ..
Hi, I am using a gridview with a templatefield containing a checkbox.
I want to update the database with a 1 or 0 depending on if a checkbox
is checked or unchecked (then use the 1 or 0 later on another page)..i
have been google around and found this....
>
If e.Row.RowType = DataControlRowT ype.DataRow Then
>
Dim Chk As CheckBox = e.Row.FindContr ol("CheckBox1" )
>
just dont know what to do next...Any ideas?
>
How are you specifying where to do the update within your support table?
MyCommand.Comma ndText = "update support.support set save = 0"

I'm not an expert, but I couldn't find anything in your code (update sql
statement) that would tell the database where in the table to do the update.
Dec 12 '06 #8
Ok, im confused now..

Basically, i want a gridview with a templatefield (or checkboxfield)
with a checkbox on it that when the user clicks the checkbox it sends a
1 or 0 value back to DB (1 for checked and 0 for unchecked)
Jim in Arizona wrote:
mike7510uk wrote:
Tried that and nothing happened, it loaded page up ok and let me click
the checkboxes but no DB update
Goofy wrote:
breakpoint the line as shown below and see if you get an exception, if you
do look at the exception message and see what its telling you and go from
there.

Try

MyCommand.Execu teNonQuery() '// breakpoint it here
Catch ex as Exception

End Try


"mike7510uk " <mi********@yah oo.co.ukwrote in message
news:11******** **************@ 80g2000cwy.goog legroups.com...
Hi
I have expanded on what i had originally but still cant get it to
update DB...here is the new code i have....

Protected Sub GridView1_RowDa taBound(ByVal sender As Object, ByVal e As
System.Web.UI. WebControls.Gri dViewRowEventAr gs) Handles
GridView1.RowD ataBound

Dim MyConnection As OdbcConnection

MyConnection = New OdbcConnection( ) 'declare new connection
object

MyConnection.Co nnectionString = "" 'database connect string

MyConnection.Op en() 'open connection to database

Dim MyCommand As New OdbcCommand() 'declare new command object

MyCommand.Conne ction = MyConnection

If e.Row.RowType = DataControlRowT ype.DataRow Then

Dim Chk As CheckBox = e.Row.Cells(5). FindControl("sa ve")

If Chk.Checked = True Then
MyCommand.Comma ndText = "update support.support set
save = 1"

End If

If Chk.Checked = False Then
MyCommand.Comma ndText = "update support.support set
save = 0"

End If
MyCommand.Execu teNonQuery()

MyConnection.Cl ose()

MyCommand = Nothing

'MsgBox(Chk.Che cked)

End If

End Sub



Goofy wrote:
Well, how you do it depends on when you want to do the update. Basically
you
need to indeed find the control in the row/column. When data is bound to
the
grid, this event fires for each row bound to the control. The event args
'e'
is passed to the function and you can use this to check if the checkbox
is
checked or not.

(Not tested but something like this)

'//e contains the Item which is the current row.
dim cb as checkbox

cb= Ctype(e.item(in dexColumnNumber ).controls(1),c heckbox)

if cb.selected = true then

'//do domething

end if

HTH
<mi********@y ahoo.co.ukwrote in message
news:11****** *************** @80g2000cwy.goo glegroups.com.. .
Hi, I am using a gridview with a templatefield containing a checkbox.
I want to update the database with a 1 or 0 depending on if a checkbox
is checked or unchecked (then use the 1 or 0 later on another page)..i
have been google around and found this....

If e.Row.RowType = DataControlRowT ype.DataRow Then

Dim Chk As CheckBox = e.Row.FindContr ol("CheckBox1" )

just dont know what to do next...Any ideas?

How are you specifying where to do the update within your support table?
MyCommand.Comma ndText = "update support.support set save = 0"

I'm not an expert, but I couldn't find anything in your code (update sql
statement) that would tell the database where in the table to do the update.
Dec 13 '06 #9
I have now managed to do this (at last)
here is the code...

Protected Sub save_CheckedCha nged(ByVal sender As Object, ByVal e As
System.EventArg s)

Dim MyConnection As OdbcConnection

MyConnection = New OdbcConnection( ) 'declare new connection
object

MyConnection.Co nnectionString = " " 'database connect string

MyConnection.Op en() 'open connection to database

Dim MyCommand As New OdbcCommand() 'declare new command object

MyCommand.Conne ction = MyConnection

Dim cID As Integer = 0
' Dim str As StringBuilder = New StringBuilder
Dim i As Integer = 0
Dim state As Integer
For i = 0 To GridView1.Rows. Count - 1
'Dim row As GridViewRow = GridView1.Rows( i)
Dim isChecked As Boolean =
CType(GridView1 .Rows(i).FindCo ntrol("save"), CheckBox).Check ed
If isChecked Then
state = 1
Else
state = 0
End If

MyCommand.Comma ndText = "update support.support set save =?
where id=?"
MyCommand.Param eters.Clear()
MyCommand.Param eters.Add(New OdbcParameter(" @state",
state))
MyCommand.Param eters.Add(New OdbcParameter(" @id",
GridView1.Rows( i).Cells(0).Tex t))
MyCommand.Execu teNonQuery()
Next

MyConnection.Cl ose()
MyCommand = Nothing
End Sub

All i need to do now is if a user checks a particular checkbox, it
remains checked the next time they visit the page..

mike7510uk wrote:
Ok, im confused now..

Basically, i want a gridview with a templatefield (or checkboxfield)
with a checkbox on it that when the user clicks the checkbox it sends a
1 or 0 value back to DB (1 for checked and 0 for unchecked)
Jim in Arizona wrote:
mike7510uk wrote:
Tried that and nothing happened, it loaded page up ok and let me click
the checkboxes but no DB update
Goofy wrote:
>breakpoint the line as shown below and see if you get an exception, if you
>do look at the exception message and see what its telling you and go from
>there.
>>
>Try
>>
> MyCommand.Execu teNonQuery() '// breakpoint it here
>>
>>
>Catch ex as Exception
>>
>>
>>
>End Try
>>
>>
>>
>>
>"mike7510uk " <mi********@yah oo.co.ukwrote in message
>news:11******* *************** @80g2000cwy.goo glegroups.com.. .
>>Hi
>>I have expanded on what i had originally but still cant get it to
>>update DB...here is the new code i have....
>>>
>>Protected Sub GridView1_RowDa taBound(ByVal sender As Object, ByVal e As
>>System.Web.UI .WebControls.Gr idViewRowEventA rgs) Handles
>>GridView1.Row DataBound
>>>
>>>
>>>
>> Dim MyConnection As OdbcConnection
>>>
>> MyConnection = New OdbcConnection( ) 'declare new connection
>>object
>>>
>> MyConnection.Co nnectionString = "" 'database connect string
>>>
>> MyConnection.Op en() 'open connection to database
>>>
>> Dim MyCommand As New OdbcCommand() 'declare new command object
>>>
>> MyCommand.Conne ction = MyConnection
>>>
>>>
>>>
>> If e.Row.RowType = DataControlRowT ype.DataRow Then
>>>
>> Dim Chk As CheckBox = e.Row.Cells(5). FindControl("sa ve")
>>>
>>>
>>>
>> If Chk.Checked = True Then
>> MyCommand.Comma ndText = "update support.support set
>>save = 1"
>>>
>>>
>>>
>> End If
>>>
>> If Chk.Checked = False Then
>> MyCommand.Comma ndText = "update support.support set
>>save = 0"
>>>
>>>
>>>
>> End If
>>>
>>>
>> MyCommand.Execu teNonQuery()
>>>
>> MyConnection.Cl ose()
>>>
>> MyCommand = Nothing
>>>
>>>
>>>
>> 'MsgBox(Chk.Che cked)
>>>
>>>
>>>
>> End If
>>>
>> End Sub
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>Goofy wrote:
>>>Well, how you do it depends on when you want to do the update. Basically
>>>you
>>>need to indeed find the control in the row/column. When data is bound to
>>>the
>>>grid, this event fires for each row bound to the control. The event args
>>>'e'
>>>is passed to the function and you can use this to check if the checkbox
>>>is
>>>checked or not.
>>>>
>>>(Not tested but something like this)
>>>>
>>>'//e contains the Item which is the current row.
>>>dim cb as checkbox
>>>>
>>>cb= Ctype(e.item(in dexColumnNumber ).controls(1),c heckbox)
>>>>
>>>if cb.selected = true then
>>>>
>>>'//do domething
>>>>
>>>end if
>>>>
>>>HTH
>>>>
>>>>
>>><mi********@ yahoo.co.ukwrot e in message
>>>news:11***** *************** *@80g2000cwy.go oglegroups.com. ..
>>>>Hi, I am using a gridview with a templatefield containing a checkbox.
>>>>I want to update the database with a 1 or 0 depending on if a checkbox
>>>>is checked or unchecked (then use the 1 or 0 later on another page)..i
>>>>have been google around and found this....
>>>>>
>>>>If e.Row.RowType = DataControlRowT ype.DataRow Then
>>>>>
>>>>Dim Chk As CheckBox = e.Row.FindContr ol("CheckBox1" )
>>>>>
>>>>just dont know what to do next...Any ideas?
>>>>>
>
How are you specifying where to do the update within your support table?
MyCommand.Comma ndText = "update support.support set save = 0"

I'm not an expert, but I couldn't find anything in your code (update sql
statement) that would tell the database where in the table to do the update.
Dec 13 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2852
by: Bill44077 | last post by:
I am dynamically adding a checkbox in a gridview and I find there are several things that I cannot figure out how to address. 1. The width of the checkbox column is very wide. I've tried adding properties and Item Style to the column but it has no effect. Is there someway to size this column to be smaller? I removed the CssClass property...
0
3288
by: Jayender | last post by:
Hi , I have placed checkbox in my gridview .. now when i check the chekbox and click anybutton the checkbox becomes unchecked. but when i normally add checkbox in the page it doesnt happen but it happens when i add it to the gridview. why is that ? i have added checkbox like this in my gridview: .......
1
21458
by: mercercreek | last post by:
This one should be easy. Hope someone has a clue. Simple Scenario: Gridview with mulitple rows, each row with a checkbox. The user checks boxes of her choice. Clicks a button on the form (not in the grid). Desired aciton is then taken in response to the button_onclick event relevant to the row in which the checked checkboxes exist. ...
2
5134
by: JonBosker | last post by:
I am having a strange problem - my GridView is displaying bits (from SQL Server) as checkboxes (which is fine) but it shows each alternating one centrally aligned. Heading1 Heading2 Text Checkbox Text2 Checkbox Text3 Checkbox Text4 Checkbox
1
2388
by: Ben | last post by:
Hi, I'm designing a c# page and trying to add a checkbox column to a GridView, I've added a Template Row (as described at: http://aspnet.4guysfromrolla.com/articles/052406-1.aspx) and in the Edit Templates dragged a Checkbox into the Item Template. The new column shows up, but it's empty...no checkbox appears. Any ideas? here's the...
1
9086
by: aurovinda | last post by:
Hi I send the detail code below.I have the problem when i click the checkbox there is no effect on the gridview's row.Again after a few seconds the checkbox is automatically unchecked.There is no error shows.Please help me. ======================================= protected void rowedit(object sender, EventArgs e) { ...
1
4157
by: Danielle | last post by:
Greetings all and thanks in advance for any help you can provide. I am trying ultimately to get values from a gridview row when a checkbox on the row is checked. the problem I'm having is that after ticking the checkbox, the whole page refreshes (expectedly), the checkbox is unmarked and the response.write message displayed below never...
0
2431
by: dotnetrookie | last post by:
Hi This is my 1st post.I have two checkbox columns in gridview binded through item template. The checkboxes are Category and Subcategory. I have actually removed the duplicate values in the 1st column so that Category is listed only once for the corresponding subcategories. Now I need to make sure that the all the subcategory checkboxes to...
1
3786
by: janetb | last post by:
I have a gridview with an update capabilities - a textbox column (roomName), a dropdownlist(orgID), a dropdownlist(roomTypeID),a checkbox column (dialOut), a checkbox column (dialIn). When I try to add another checkbox column, the sql database isn't updated properly with a 0/1 or false/true but with null. I've tried everything I can think of. Can...
0
7915
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8205
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8339
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8220
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6619
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5712
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3840
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3872
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.