locked
Gridview - Bind XML Attributes to control RRS feed

  • Question

  • I am trying to bind the content of an XML document to a Gridview control.   When executing the code below against the XML the only thing rendered on the page is DATAROW_ID 0.

    Code snippet:

     

     

    string dataXML2 = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Grid><DataRow><DataItem name=\"SMO_ANALYST\">CHRISTINE PEZINO</DataItem><DataItem name=\"SMO_RATING\">BUY</DataItem><DataItem name=\"NY_ANALYST\">NA</DataItem><DataItem name=\"NY_RATING\">NA</DataItem></DataRow></Grid>";

     

     

     

    //Convert the XML data into a DataSet object
    XmlReader datasetReader2 = XmlReader.Create(new StringReader(dataXML2));
    DataSet displayDS2 = new DataSet();
    displayDS2.ReadXml(datasetReader2);
    //I assign the results of the query to the GridView control GridView2.DataSource = displayDS2;
    //DataBind causes the data to display on the web form
    GridView2.DataBind();

    Thx

    • Moved by eryang Tuesday, March 2, 2010 6:32 AM (From:.NET Base Class Library)
    Monday, March 1, 2010 3:46 PM

Answers

  • First of all, you should use the other forum for questions related to ASP.NET.   Use the ASP.NET forum.
    Try binding the DataGridView to a table within your DataSet instance.

    GridView2.DataSource = displayDS2.Tables[0];


    Mark the best replies as answers. "Fooling computers since 1971."
    Monday, March 1, 2010 5:18 PM
  • This was moved out of the .NET forum.

    You can ask this in an ASP.NET forum (as suggested).

    Or I can move it into a specific MSDN forum if you'd like.

    This is regarding your code:

    string dataXML2 = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Grid><DataRow><DataItem name=\"SMO_ANALYST\">CHRISTINE PEZINO</DataItem><DataItem name=\"SMO_RATING\">BUY</DataItem><DataItem name=\"NY_ANALYST\">NA</DataItem><DataItem name=\"NY_RATING\">NA</DataItem></DataRow></Grid>"; 
    

     

    Thanks!
    Ed Price a.k.a User Ed, Microsoft Experience Program Manager (Blog, Twitter, Wiki)
    Friday, December 30, 2011 3:49 AM

All replies

  • First of all, you should use the other forum for questions related to ASP.NET.   Use the ASP.NET forum.
    Try binding the DataGridView to a table within your DataSet instance.

    GridView2.DataSource = displayDS2.Tables[0];


    Mark the best replies as answers. "Fooling computers since 1971."
    Monday, March 1, 2010 5:18 PM
  • This was moved out of the .NET forum.

    You can ask this in an ASP.NET forum (as suggested).

    Or I can move it into a specific MSDN forum if you'd like.

    This is regarding your code:

    string dataXML2 = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Grid><DataRow><DataItem name=\"SMO_ANALYST\">CHRISTINE PEZINO</DataItem><DataItem name=\"SMO_RATING\">BUY</DataItem><DataItem name=\"NY_ANALYST\">NA</DataItem><DataItem name=\"NY_RATING\">NA</DataItem></DataRow></Grid>"; 
    

     

    Thanks!
    Ed Price a.k.a User Ed, Microsoft Experience Program Manager (Blog, Twitter, Wiki)
    Friday, December 30, 2011 3:49 AM