Linq – Error: Both DataSource and DataSourceID are defined on ‘GridView2’. Remove one definition.

asp.netgridviewlinq

when I write this query (using LINQ):

        Dim hw22 = From hw In db.HWs _
                   Select hw

then:

        GridView2.DataSource = hw22
        GridView2.DataBind()

this error occurs: http://www.rofof.com/img2/6hscmu7.gif

How can I solve this?

Best Solution

If you don't want to remove it in markup then do this:

GridView2.DataSourceID = ""
GridView2.DataSource = hw22
GridView2.DataBind()