none
Error: Both DataSource and DataSourceID are defined on 'GridView1'. Remove one definition.

    Question

  • Hi,

    I got the following error at the "Controls.Add(control);" line. And the setup of GridView1 is shown below. What's wrong with it?
    "Both DataSource and DataSourceID are defined on 'GridView1'.  Remove one definition."

    Control control = Page.LoadControl(_ascxPath);
    Controls.Add(control);<-- Error occurs

    setup of GridView1
    DataContext dc = new DataContext(DataConnection);
    var summaries = (from p in dc.EmployeeDependents
    where p.employee_id == a
    select p);


    GridView1.DataSourceID = String.Empty;
    GridView1.DataSource = summaries;
    GridView1.DataBind();

     

    Monday, May 31, 2010 7:06 PM

Answers

  • Actually, this works and the only reason it was not working previously was the database connection was incorrect, so it gave out the same error message.

    GridView1.DataSourceID = String.Empty;
    GridView1.DataSource = summaries;

    • Marked as answer by wkpli Wednesday, June 16, 2010 2:36 PM
    Wednesday, June 16, 2010 2:36 PM

All replies

  • I guess you should remove the following line:

    GridView1.DataSourceID = String.Empty;

    The error message seems pretty self-explanatory, unless of course you have tried removing the above line and still receive the same error message.


    Read my wiki at www.intheknow.it for more code and tips for developing with SharePoint 2007 & 2010
    Twitter: @starznet

    Technical Architect at Starznet Ltd. WSS/MOSS development and customisation with a primary focus on CMS.
    Monday, May 31, 2010 7:15 PM
  • That is not it. I used not to have that line. I was doing some research and find out some ppl got this resolved by added this extra line. But for me, it doesn't work anyway. I am still getting the same error even though the line is removed.

     Please help.

    Monday, May 31, 2010 7:29 PM
  • Are you perhaps setting a value on the DataSourceID property elsewhere? Earlier in the code, or maybe in the ascx markup itself?


    Read my wiki at www.intheknow.it for more code and tips for developing with SharePoint 2007 & 2010
    Twitter: @starznet

    Technical Architect at Starznet Ltd. WSS/MOSS development and customisation with a primary focus on CMS.
    Monday, May 31, 2010 8:10 PM
  • The datasourceID properties is empty in the ascx and this is the only point (lines of code listed above) I setup the binding...Any idea? It used to work before ( I should say in another dev machine)

    Thanks in advance.

    Tuesday, June 01, 2010 1:00 PM
  • Hi, wkpli

     

          I also tested your sample in my server.

          As you mentioned, set GridView1.DataSourceID = String.Empty or null would help to void data source conflict in Design-Time and Run-Time.

          I’m afraid this was not caused by logic, so where did you do this test?

          Have you checked the DLL version of this page? Is it possible that test-version and deploy-version are different?

          Clean-->rebuilt-->redeploy the solution and have a try.

         

    Best Regards,

    Aaron

    Wednesday, June 02, 2010 8:06 AM
  • Actually, this works and the only reason it was not working previously was the database connection was incorrect, so it gave out the same error message.

    GridView1.DataSourceID = String.Empty;
    GridView1.DataSource = summaries;

    • Marked as answer by wkpli Wednesday, June 16, 2010 2:36 PM
    Wednesday, June 16, 2010 2:36 PM
  • Hi,

    you will get this message when the summeries resultset (from database)is null.

    Monday, August 15, 2011 8:22 PM