Search code examples
c#asp.netaspxgridview

Are there any hack methods for accessing a parent property declared as internal?


The problem is I have AspxGridView with Bands and Columns. I need to add Bands (class GridViewBands) with ColRowSpan = 2, but this property exists only in parent class - GridViewColumn. GridViewColumn has property ColRowSpan, but it is declared as "protected internal". Also, I tried to access it during debug - it works! But in the code I got exception.

Please, let me know does any method exist to access and change this property?

enter image description here


Solution

  • I found the solution. It needs to use Reflection in this case. The code will be like this:<b

    var gridViewColumnType = typeof(GridViewColumn);
    var cellRowSpanProperty = gridViewColumnType.GetProperty("CellRowSpan", BindingFlags.Instance | BindingFlags.NonPublic);
    cellRowSpanProperty.SetValue(bandcolumn, 2);