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?
Thank You
Stephen Sjostrom
Hello Stephen,
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;
if (parentRow.HasRowIslands)
return parentRow.RowIslands[0].Rows[childRowIndex].Items.Cast<GridRecordItem>().Select(i => i .Value.ToString());
}
return null;
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.
HiGalina,
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?
Thank you
Hi Stephen,
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.
Hi Galina,
Here is my code section. I'm unsure of what you mean about making it a public method.
Protected Sub btnPrint_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrint.Click
Dim activeCell As GridRecordItem Dim activeRowIndex As int Try
activeCell = wdgTimeRptGroup.GridView.Behaviors.Activation.ActiveCell activeRowIndex = activeCell.Row.Index Dim rowValues = GetChildRowValues(activeRowIndex, 0)
Catch ex As Exception
End Try End Sub
Depending on your application's structure and where you call the method from, you need to adjust the access modifiers of your methods & properties. In my initial response I sent you the GetChildRowValues method with the following signature:
In this line, I suggest you try changing protected to public so the access to this method has no restrictions at all.
public IEnumerable<string> GetChildRowValues(int parentRowIndex, int childRowIndex)
You may refer to the Accessibility Levels topic for more details.
Let me know if I may be of any further assistance.
Sorry for the delay but the following line returns activecell = nothing. Can you point into the right direction of what maybe the problem?
activeCell = wdgTimeRptGroup.GridView.Behaviors.Activation.ActiveCell
If there is no active cell in the grid, then the line you mention would return nothing. I suggest you check it is not 'Nothing' before you proceed with getting the row and its values.
As I mentioned in my previous reply, I am using the active cell as an example but you will have to adapt the code to get the cell of interest as per your application's requirements.