DELETE MORE THAN ONE ROW OF DATAGRID

C

Charleees

Hi all,

I have a DataGrid With Template Columns..
In the First Column i have a Check Box...

Also i have a Button Outside the DataGrid..Just Above it..

What i want to do is ....

I have to remove the Rows(Records) that are Checked in the Grid...

There may be more than 1 ChecBox Checked..

How could i do this..

ITs URgent..

Please Help..

Thanks in Advance..
Sanju.C
 
P

pradeep10

Hello Charlees

On the DataItemBound you have to create a CheckBox dynamically and u
have to find the the checkbox which is checked from ther u can delete
the rows

here is the coding for that
CheckBox ch =
(CheckBox)grid.Tables["tablename"].coloumns["coloumnname"].Cells(0).FindControl("CheckBoxname");
if(ch.Checked)
then write code for delete
 
C

Charleees

Hi ,

I have to determine the Checked Check Boxes and using it the
corresponding DataGrid Rows.. On Delete Buton Click...

But item bound will not be called on ButtonClick Outside the Grid..

Then how could i Determine the CheckBoxes Checked and corresponding
Row..

Please Reply..

Sanju.C
 
B

bmicks

I've done this in the past:

Assuming that you're setting the DataKeyField when databinding, you can
use code similar to the following on the button's click event -

private void dgDelete_OnClick(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
foreach( DataGridItem item in dg.Items )
{
HtmlInputCheckBox chkBox =
(HtmlInputCheckBox) item.FindControl("checkboxCol");

//If it's selected then delete it
if ( chkBox != null && chkBox.Checked )
{
int objectID =(int)dg.DataKeys[(int)e.Item.ItemIndex];
//call delete code here for the given objectID
}
}
}
 

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,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top