Idea for GridView to encapsulate Datasource - How to?? RRS feed

  • Question

  • User-515897137 posted

    I have been asked to extend a grid view control so that the control lknows how to fetch its own data without having to provide it a data source control of any description.  The data will infact ultimately come back from a Linq o Entities object, however I am expecting it to be of the type MaterializedDataRecord

    Although this idea doesn't feel right, I am not sure how to start as the GridView does not try to render anything if the datasource has not ben set.  How would you go about this task?

    Any comments regarding the merits or not for this idea welcome...

    Tuesday, March 18, 2008 9:24 AM

All replies

  • User300685930 posted

    You could in the oninit of your extended control, simply set this.datasource = Some Generic List of a known type, then poplulate it.

    That is


    where MyRec is a class with attributes.

    Tuesday, March 18, 2008 9:27 AM
  • User-515897137 posted

    Thanks for this.  Maybe is is not such a bad idea after all.

    I have since extended a web.ui.gridview control to have an ObjectContainerDatasource object embedded to get data from the entity framework via an "Adapter" class.

    The extended control uses reflection to create an instance of the adapter and call the CreateInstance() method to obtain information about the Entity Object we are adapting. in the OnInit() method as suggested


    IVGridDataAdapter dataAdapter = CreateDataAdapter();

    this.DataObjectTypeName = dataAdapter.DataTypeName;

    this.DataSource = this.dataSourceControl;

    The bolded line is the bit that goes out to the entity framework to retrieve a suitable object to represent in the control.  At design time, I am seeing 

    "The specified named connection is either not found in the configuration, not intended to be used with the EntityClient Provider, not valid.",    where I should be seeing the control rendering in design time.  At run time, this all works fine using only this adapter mechanism.

    The c/s/m files are kept in the App_Data folder of my asp.net 3.5 web application.

    Why might the control complain only at design time?  The string is valid but I am confused by the part "...not intended to be used with the EntityClient Provider...".    Am I breaking a rule here? 
    Could this be happening because the connection string isn't being "read" from the web.config at design time? 

    Any suggestions?


    Note, I have also cross posted this one to the ADO.Net team



    Wednesday, March 19, 2008 2:32 AM