How can i iterate over a DataGrid?

Results 1 to 2 of 2

Thread: How can i iterate over a DataGrid?

  1. #1
    Join Date
    Dec 1969

    Default How can i iterate over a DataGrid?

    Hi everyone...i have a datagrid with a column of checkbox, I want to let the user select the checkboxes he need and then, by pressing a button, I need to iterate trough all the datagrid to detect wich ones have been selected and then do an other DataSet with question is how can i do this, the iterating trough a DataGrid rows....its this possible??...any ideas??, please!!...<BR>Thank You All

  2. #2
    Join Date
    Dec 1969

    Default RE: How can i iterate over a DataGrid?

    Couple ways.<BR><BR> for (int i = 0; i &#060; myGrid.Items.Count; i ++)<BR> {<BR> CheckBox mycheckBox = myGrid.Items[i].FindControl("myCheckBox") as CheckBox;<BR> if (myCheckBox != null)<BR> {<BR> if (myCheckBox.Selected)<BR> { <BR> // do stuff;<BR> }<BR> }<BR> }<BR><BR>or, <BR><BR>When a datagrid is bound, as it iterates over each row binding it, it fires the OnDataBound event. You can specify a handler for this event and check either the:<BR><BR>DataItem object exposed by the DataGridItemEventArgs property, where DataItem represents the current Row from your datasource OR <BR>you can use the e.Item.FindControl() method to find the checkbox and check for its value.<BR><BR>-Kevin Mesiab<BR>

Posting Permissions

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