I have a WebHierarchicalDataGrid and I need to get values from the cells in the child row when a user click on a button outside of the grid. Can any one point me in the right direction on how to accomplish this?
In order to get the values of child row cells (server side) you need to get the child row itself and extract the values of its Items collection. The code should look similar to the following:
protected IEnumerable<string> GetChildRowValues(int parentRowIndex, int childRowIndex)
var parentRow = (ContainerGridRecord)hierDataGrid.GridView.Rows[parentRowIndex];
parentRow.Expanded = true;
return parentRow.RowIslands.Rows[childRowIndex].Items.Cast<GridRecordItem>().Select(i => i .Value.ToString());
More detailed information on working with rows and row islands is available in the About WebHierarchicalDataGrid topic. If you have any further questions on the matter, please, let us know.
Thank you for the information. I'm calling the code from a ASP Button so if I was going to use the example you sent where do I get the parentRowIndex and/or childRowIndex from?
The actual parent and child rows would depend on your application's requirements. As you mentioned using a button outside of the grid I assume you will need to execute this code for the selected/active row or some other specified elsewhere grid row. So, in case you are interested in the active row and its first child, you should have the following code for the Button click:
protected void Button_Click(object sender, EventArgs e)
GridRecordItem activeCell = hierDataGrid.GridView.Behaviors.Activation.ActiveCell;
int activeRowIndex = activeCell.Row.Index;
var rowValues = GetChildRowValues(activeRowIndex, 0);
Let me know if I misunderstood something and you need further assistance on the matter.
I'm following you here but I have on problem left. I receive the following message when I try to compile.
Severity Code Description Project File Line Suppression StateError BC30451 'GetChildRowValues' is not declared. It may be inaccessible due to its protection level.
You may try making the method public instead of protected and see if the problem goes away. Let me know what the result is. Looking forward to hearing from you.