Datagrid checkbox question

H

Hennie

How can I use a checkbox to trigger an add / delete procedure on a datagrid?

If the checkbox is checked a field in the datagrid row and a session id must
be saved to another table.

The problem is the datagrid row is not selected first, so how do I get the
field value from the row the checkbox was checked in?

Thanks
 
E

Eliyahu Goldin

The obvious answer is you should setup an server-side onclick event handler.
The event handler will get as a parameter a reference to the checkbox that
initiated the event. If the checkbox is in a table cell, it will be a child
control for its parent cell. And the parent cell is a child control for its
parent row. That's how you can get to the row.

Eliyahu
 
K

Kareem Mostafa

You need to have a server side function or a if(Page.IsPostBack) and
then u loop through the rows of the datagrid and see cast the contents
of the cell having the checbox into a checkbox control and see if it's
checked or not...something like this

foreach(DataGridItem dtmItem in dtgRecords.Items)
{

if(dtmItem.ItemType == ListItemType.Item || dtmItem.ItemType ==
ListItemType.AlternatingItem)
{
CheckBox cbxRecord =
(CheckBox)dtmItem.Cells[0].FindControl("cbxRecord");
if(cbxRecord.Checked)
{
// Do whatever you want on this row
}
}
}

Hope it works...
Kareem Mostafa
 

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,770
Messages
2,569,584
Members
45,079
Latest member
ElidaWarin

Latest Threads

Top