?
Solved

Unable to view gridview that has datasource from LINQ query

Posted on 2011-02-23
5
Medium Priority
?
882 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month11 days, 20 hours left to enroll

752 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