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. Advertising

  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. 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. mehul
    Replies:
    0
    Views:
    767
    mehul
    May 3, 2004
  2. yurps
    Replies:
    1
    Views:
    6,899
    rajeshthangarasu1983
    Feb 29, 2008
  3. Jon
    Replies:
    5
    Views:
    189
    Ken Cox [Microsoft MVP]
    Sep 18, 2003
  4. Replies:
    5
    Views:
    168
    James Edward Gray II
    Jul 17, 2007
  5. randy
    Replies:
    13
    Views:
    452
    Tad McClellan
    Nov 1, 2003
Loading...

Share This Page