473,378 Members | 1,451 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Datagrid checkbox question

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

Nov 19 '05 #1
2 1159
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

"Hennie" <sp*****@linux.com> wrote in message
news:eK**************@TK2MSFTNGP10.phx.gbl...
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

Nov 19 '05 #2
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

Nov 19 '05 #3

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

Similar topics

1
by: Joe Bloggs | last post by:
I am trying display the contents of a table in a web page, select certain rows from that table and then display the fields that I have selected (now table columns) as text in a Label object....
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
1
by: iforsyth | last post by:
Have a paging datagrid with a checkbox control in column(0). ViewState is enabled. I check the checkbox in first row of the grid on a page and then the program hits this event: Private Sub...
1
by: Machi | last post by:
Let say i select rows of records with 4 columns from Database and want to display the data in DataGrid (ASP.NEt Server Control) with one column which must be displayed in CheckBox layout. For the...
4
by: Mike | last post by:
Hi, Is there a possibility to have one of the Web Control Datagrid's column as a Calendar when editing data? Any resources on this subject? Thanks Mike
6
by: jiangyh | last post by:
hi there: I have a datagrid in my web form that contain a templet column.And in this templet column have a checkbox web control.I will get the checkbox state in my serverside. My question is...
10
by: Jennyfer J Barco | last post by:
Hello, I have a datagrid that brings some information from a query. I need to have a checkbox in each row so the user can select the rows he wants to reprint. Is it possible to have a checkbox...
0
by: Rudy | last post by:
Hello all, I have a datagrid with a checkbox as a template. I connected my two chekboxes in the template to my my datasource in the propeties menu. But I get this error flagged at line 33....
2
by: Nu2ASP.NET | last post by:
What I am trying to do is essentially 'flip' the bits, when the user clicks in the checkbox. For example, if the CheckBox appears checked, and the user un-checks it, I want the underlying data...
17
by: Mike Fellows | last post by:
im trying (unsucessfully) to add a checkbox column to my datagrid i basically have a datagrid that im populating from a dataset Me.DataGrid1.DataSource = ds.Tables(0) the datagrid then has 5...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.