DELETE MORE THAN ONE ROW OF DATAGRID

  • Thread starter Thread starter Charleees
  • Start date Start date
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
 
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
 
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
 
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
}
}
}
 
Back
Top