DataGrid with CheckBox - How to read checked rows

Ask a Question related to ASP.NET Data Grid Control, Design and Development.

  1. #1

    Default DataGrid with CheckBox - How to read checked rows

    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 Guest

  2. Similar Questions and Discussions

    1. Summarize values when checkbox is checked
      Hello all, The output of some query shows for example 10 records with invoice prices. Before each record is an unchecked checkbox. What I like to...
    2. Howto bind CheckBox to the datagrid/ Then update the database field when the checkbox is clicked.
      I am trying to update the database field when the checkbox is clicked. I am trying to modified the following solution but.. got stuck on the...
    3. Saving checkbox states (checked or unchecked)?
      Hello. I'm creating a basic form with checkboxes for "yes/no". Is there a way for the state of the checkboxes to be saved by the user (using regular...
    4. Find what checkbox is checked in javascript
      I have to sets of checkboxes. The second is to delete the row. So when I click that checkbox I want to add it to an array. I also need to take it...
    5. Capturing checked event for Template based checkbox.
      Getting to grips with the datagrid better than I thought, however I've hit another problem which hopefully someone will be able to help (again.) ...
  3. #2

    Default Re: DataGrid with CheckBox - How to read checked rows

    > 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
    [url]http://staff.develop.com/ballen[/url]




    Brock Allen Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139