I have a grid bound to a WebHierarchichalDataSource. I want to change the data field that one column is bound to according to a users choice.
I have tried setting the data field for the column like thisNewGrid.Columns(NoteCol).Key = "DueNote"or like thisNewGrid.GridView.Columns(NoteCol).Key = "DueNote"
And I either see no change or the error "Object reference not set to an instance of an object". I have tried setting the value in various places during DataBind and in Data_bound but get the same error.I feel I need to set the DataFieldName for the column but DataFieldName is not a member of Columns (although it appears to be in the designer) and I can find no way to set this server side.
I have found the solution. Define a variable as a BoundDataField and use that to set the DataFieldName.
Dim bf as BoundDatafield
bf =NewGrid.Columns(3)
bf.DatafieldName = "[anotherfieldName]"
I suppose this cannot be accessed directly from the Column because the column could be different types (e.g. BoundCheckBoxField) of bound or unbound datafield.
Amazing how cathartic posting a question can be! I spent hours before posting trying to solve this and yet solved it minutes after.
You basically did exactly what I said to do. Like I said, when you access the columns from the Columns collection, we return it as a GridField, because that is the common class for all types (bound, unbound, template, and the checkboxes). So you can only access common properties (header, css, tooltip). You need to cast to the appropriate type before accessing column specific properties. You have accomplished it in a different way, but it works.
-Dave