Checkbox in a Datagrid, how to handle PostBack

  • Thread starter Thread starter DotNetDev
  • Start date Start date
D

DotNetDev

Hi,

Does any one have an example of using Checkboxes in Datagrid?

I want to have postback enabled for each single checkbox and then execute
the code accordingly. Instead of having a button and looping through the list
of checkboxes to check if its clicked.
 
You need to create a template column for the field you wish to use as checkbox.
Replace the label and textbox with a checkbox the you will have to write
some code against it to retrieve the data

example:
Protected Sub Button1_Click(ByVal sender as Object, ByVal e as
System.EventArgs) handes Button1.Click

Dim myItem as DataGridItem = DataGrid1.Items(1)
dim myID as string = myItem.Cells.Item(0).Text
dim myProd as string = myItem.Cells.Item(1).Text
dim myChk as CheckBox = myItem.Cells.Item(2).FindControl("CheckBox2"),
CheckBox)

dim mybool as Boolean = myChk.Checked

Assumptions:
Retrieving three columns from Products table in Northwind
1 - ProductID
2 - ProductName
3 - Discontinued

Mounually bound these columns
convert the third into a templates

That's pretty much it.
 
Back
Top