Solved

Unable to view gridview that has datasource from LINQ query

Posted on 2011-02-23
5
871 Views
Last Modified: 2012-05-11
"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

0
Comment
Question by:Michael Roodt
5 Comments
 
LVL 22

Expert Comment

by:Mrunal
ID: 34967366
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 34969379
You might have better luck with an XmlDataSource, and a valid XPath expression...
0
 
LVL 27

Expert Comment

by:MikeToole
ID: 34969897
Try this:
        GridView1.DataSource = result.ToList()

0
 
LVL 2

Accepted Solution

by:
Michael Roodt earned 0 total points
ID: 34980664
Thanks for your suggestions. I eventually gave up on that method and ended up using xmldocument and searched through the elements instead
0
 
LVL 2

Author Closing Comment

by:Michael Roodt
ID: 35015445
Attempted a different method to the problem
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question