How to use Button control, with checkboxes in a datagrid

S

Stafarian

I'll keep this simple. I have a datagrid with checkboxes coded in my
Itemtemplate control. How do I wire up a button control to the datagrid, so
that if I select one or more checkboxes it deletes that row? Here is the Sub
from that button

Protected Sub Delete_User(ByVal sender As Object, ByVal e As EventArgs)
Dim xbox1 As CheckBox = CType(sender, CheckBox)
Dim dgItem As DataGridItem = CType(xbox1.NamingContainer, DataGridItem)
if xbox1.checked then
redlabel.Text = "You selected row " & dgItem.Cells(1).Text
end if

End Sub
 
P

Phillip Williams

If you want the checkbox event handler to do the delete per postback then the
button that causes the postback needs not process any action concerning
deleting the records. I have at this link an example that does this (among
other things):
http://www.societopia.net/Samples/DataGrid_ChildControlsEvents.aspx

If you want the delete button to process the delete task then the only
difference is that you would loop through the datagrid items to find out
which checkbox was checked.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top