DELETE MORE THAN ONE ROW OF DATAGRID

Discussion in 'ASP .Net' started by Charleees, Jun 16, 2006.

  1. Charleees

    Charleees Guest

    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
     
    Charleees, Jun 16, 2006
    #1
    1. Advertising

  2. Charleees

    Guest

    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

    Charleees wrote:
    > 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
     
    , Jun 16, 2006
    #2
    1. Advertising

  3. Charleees

    Charleees Guest

    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
     
    Charleees, Jun 16, 2006
    #3
  4. Charleees

    Guest

    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
    }
    }
    }
     
    , Jun 16, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Dalberg
    Replies:
    0
    Views:
    383
    John Dalberg
    Dec 20, 2005
  2. tom
    Replies:
    5
    Views:
    410
  3. Merciadri Luca
    Replies:
    4
    Views:
    821
  4. Steven D'Aprano
    Replies:
    0
    Views:
    99
    Steven D'Aprano
    Dec 23, 2013
  5. Replies:
    3
    Views:
    89
    Gary Herron
    Dec 23, 2013
Loading...

Share This Page