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
903
Change the data field for a column server side
posted

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 this

NewGrid.Columns(NoteCol).Key = "DueNote"

or like this

NewGrid.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.



Parents
  • 903
    posted

    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.

Reply Children