Solved

Unable to view gridview that has datasource from LINQ query

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

Turn Insights into Action

Communication across every corner of your business is essential to increase the velocity of your application delivery and support pipeline. Automate, standardize, and contextualize your communication processes with xMatters.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

695 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