Solved

Unable to view gridview that has datasource from LINQ query

Posted on 2011-02-23
5
861 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

867 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now