Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
400
Iterate child rows in WHDG
posted

Hello,

I've added an unboundcheckboxfield to my WebHierarchicalDataGrid child rows and trying to access each after a button click.  Because of the way the checkbox field was added, I don't know what the ID of the control is:

Here's how the checkbox is added:

InventoryGrid.Bands.Add(childBand);

UnboundCheckBoxField cbf = new UnboundCheckBoxField();
cbf.Key = "ID";
cbf.Width = 25;
InventoryGrid.Bands[0].Columns.Add(cbf);
InventoryGrid.Bands[0].AutoGenerateColumns = false;

Here's my button click event:

foreach (ContainerGridRecord gridRow in InventoryGrid.GridView.Rows)
{
if (gridRow.HasRowIslands)
{
ContainerGridRecordCollection childRows = gridRow.RowIslands[0].Rows;
//If the current row has RowIslands, iterate through row island rows
foreach (ContainerGridRecord row in childRows)
{
CheckBox cb = (CheckBox)row.Items[2].FindControl("CheckBox1");
cb.Checked = true;
}
}
}

I can loop through all the rows and child rows, but how can I find a control without knowing the name or ID?  I need to find all the rows where the checkbox is checked.

Thank you,

Steve

Parents
  • 2095
    posted

    Hi Steve,

    Thank you for posting in the community.

    You actually do not need the ids of the rows to get their checkbox values.

    When grid column is set to UnboundCheckBoxField, its property Value is Boolean representation of whether checkbox is checked. 

    So in you case you can iterate the rows and just check the following

    1. row.Items[2].Value

    Also I'm sending you a similar post from our forum which may helps you in you future implementations:

    How to get Checked Rows in Webdatagrid in ClientSide/ServerSide Code

    Please let me know if this helps.

Reply Children
No Data