Checkbox in a Datagrid, how to handle PostBack

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.
 
A

Angel

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.
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top