Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6584861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:35:24+00:00 2026-05-25T16:35:24+00:00

I am trying to use LINQ to populate a GridView. My XML looks like

  • 0

I am trying to use LINQ to populate a GridView. My XML looks like this:

      <?xml version="1.0" ?> 
- <!-- Created @ 9/14/2011 1:16:52 PM
  --> 
- <DoctorList>
- <Doctor ID="1" Specialist="Dentist">
  <Username>Ahmed</Username> 
  <Password>12345</Password> 
  </Doctor>
- <Doctor ID="2" Specialist="oculist">
  <Username>Aya</Username> 
  <Password>12345</Password> 
  </Doctor>
- <Doctor ID="3" Specialist="surgery">
  <Username>malak</Username> 
  <Password>12345</Password> 
  </Doctor>
  </DoctorList>

I’m using the following code:

IEnumerable<XElement> matches = from Doctor in doc.Descendants("Doctor") where (int)Doctor.Attribute("ID") > 1 select Doctor;
GridView1.DataSource= matches;
       GridView1.DataBind();

This returns an error that the column “specialist” is not found. I want to display the specialist, id attribute and all of the inner elements. My gridview is like so:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"  
            CellPadding="4" HeaderStyle-BackColor="blue" HeaderStyle-ForeColor="White" 
            HeaderStyle-HorizontalAlign="Center" HeaderStyle-Font-Bold="True" 
            ondatabound="GridView1_DataBound">
            <Columns>  
            <asp:BoundField HeaderText="Specialist" DataField="Specialist" /> 
            <asp:BoundField HeaderText="ID" DataField="ID" ItemStyle-HorizontalAlign="Right" />
            <asp:BoundField HeaderText="Username" DataField="Username" ItemStyle-HorizontalAlign="Right" />
            <asp:BoundField HeaderText="Password" DataField="Password" ItemStyle-HorizontalAlign="Right" />
             </Columns>

<HeaderStyle HorizontalAlign="Center" BackColor="Blue" Font-Bold="True" ForeColor="White"></HeaderStyle>
           </asp:GridView>

I also made sure that matches return a value.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T16:35:25+00:00Added an answer on May 25, 2026 at 4:35 pm

    Try

    IEnumerable<XElement> matches = 
                   from Doctor in doc.Descendants("Doctor") 
                   where (int)Doctor.Attribute("ID") > 1 
                   select new {
                                  Specialist = Doctor.Attribute("Specialist").Value,
                                  ID = Doctor.Attribute("ID").Value,
                                  Username = Doctor.Element("Username").Value,
                                  Password = Doctor.Element("Password").Value
                    };
    
    GridView1.DataSource = matches;
    GridView1.DataBind();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use LINQ to XML to create an Excel spreadsheet. I created
I'm trying to get this sitemap clas s working. It appears to use LINQ,
I am trying to use LINQ to XML in an with the XDocument object.
Possible Duplicate: Use LINQ to read all nodes from XML I am trying to
Trying to use Linq to XML for the first time and having some problems.
I'm trying to use LINQ to bind the data in my GridView. In my
I am trying to use Linq to XML to save & retrieve some HTML
I am trying to populate table ussing LINQ to SQL , I use the
I'm trying to use Linq on this project. Therefore I need the database to
I am trying to use linq to xml functional construction to create xml from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.