Unable to view gridview that has datasource from LINQ query

"The data source for GridView with id 'GridView1' did not have any properties or attributes from which to generate columns.  Ensure that your data source has content."


If I look at the values held in result, it looks like everything gets populated but for some reason it crashes with the above error. when it hits gridview1.databind()

I have tried adding GridView1.AutoGenerateColumns = False but  and my webpage does load but there is no gridview visible
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


        Dim ds As New DataSet
        ds.ReadXml("http://repecomm/xml/ftptransfers_01_2011.xml")

        Dim result = From q In ds.Tables(0).AsEnumerable
                     Where q.Item("id").ToString.StartsWith("Web")
                     Select New With {.id = q.Item("id")}

        GridView1.DataSource = result

        GridView1.DataBind()
        GridView1.AutoGenerateColumns = False

    End Sub

Open in new window

LVL 2
Michael RoodtSenior .NET Integrations DeveloperAsked:
Who is Participating?
 
Michael RoodtConnect With a Mentor Senior .NET Integrations DeveloperAuthor Commented:
Thanks for your suggestions. I eventually gave up on that method and ended up using xmldocument and searched through the elements instead
0
 
MrunalCommented:
hi
can you post your aspx design code for gridview?

just try by setting, AutoGenerateColumns = True

If this is populating data and if you are using AutoGenerateColumns = False for GridView1 then you have to manually declare columns in <Columns> tag for the same.

see:

http://msdn.microsoft.com/en-us/library/aa479342.aspx

http://authors.aspalliance.com/aspxtreme/sys/web/ui/webcontrols/GridViewClassAutoGenerateColumns.aspx


0
 
Bob LearnedCommented:
You might have better luck with an XmlDataSource, and a valid XPath expression...
0
 
MikeTooleCommented:
Try this:
        GridView1.DataSource = result.ToList()

0
 
Michael RoodtSenior .NET Integrations DeveloperAuthor Commented:
Attempted a different method to the problem
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.