DataGrid with CheckBox - How to read checked rows

Discussion in 'ASP .Net Datagrid Control' started by Magnus, May 18, 2005.

  1. Magnus

    Magnus Guest

    I have added a checkbox to a dataset that I bind to a datagrid:

    DataColumn colBoolean = new DataColumn ("chkBox");
    colBoolean.DataType = System.Type.GetType ("System.Boolean");
    colBoolean.DefaultValue = true;
    ds.Tables["etikett"].Columns.Add (colBoolean);

    grd.DataSource = ds.Tables["etikett"].DefaultView;
    grd.DataBind();

    How do I read all the rows that have been checked? I want to create a
    report (crystal) for only the checked rows.

    Regards,
    Magnus
     
    Magnus, May 18, 2005
    #1
    1. Advertisements

  2. Magnus

    Brock Allen Guest

    > How do I read all the rows that have been checked? I want to create a
    > report (crystal) for only the checked rows.


    You'll have to loop over the rows in the DataGrid and access the Cell that
    contains the checkbox. Once you have the cell, use FindControl("YourCheckBoxID")
    to get the CheckBox control then get its Checked property.

    // pseudocode
    foreach (DataGridRow row in grid.Rows)
    {
    Control c = row.Cells[TheIndexOfYourCheckBoxColumn].FindControl("YourCheckBoxID");
    CheckBox cb = c as CheckBox;
    if (cb != null && cb.Checked)
    {
    // this row has been selected
    }
    }

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen
     
    Brock Allen, May 18, 2005
    #2
    1. Advertisements

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. Matthew Louden

    checkbox checked change event question

    Matthew Louden, Nov 18, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    5,570
    Teemu Keiski
    Nov 18, 2003
  2. mehul
    Replies:
    0
    Views:
    903
    mehul
    May 3, 2004
  3. yurps
    Replies:
    1
    Views:
    7,598
    rajeshthangarasu1983
    Feb 29, 2008
  4. =?Utf-8?B?RG90TmV0RGV2?=

    DataGrid and embeded Checkbox..How to find if checkbox clicked

    =?Utf-8?B?RG90TmV0RGV2?=, Oct 6, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    1,027
    David Wier
    Oct 6, 2006
  5. Joey Pang
    Replies:
    4
    Views:
    853
    Joey Pang
    Jun 13, 2005
  6. Jon
    Replies:
    5
    Views:
    292
    Ken Cox [Microsoft MVP]
    Sep 18, 2003
  7. Replies:
    5
    Views:
    338
    James Edward Gray II
    Jul 17, 2007
  8. randy
    Replies:
    13
    Views:
    781
    Tad McClellan
    Nov 1, 2003
Loading...