How to bind xml to gridview

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tomlor1980
    New Member
    • May 2010
    • 2

    How to bind xml to gridview

    I'm new to asp.net and i'm trying to bind some XML data to a gridview.
    abviously I'm not understanding how to do it properly because that my code doesn't seem to
    work...Can anyone could help me please?

    this is my xml:
    Code:
    #########################################
    <?xml version "1.0" encoding "utf-8"?>
    <dictionary>
      <item>
    	<key>
    	   <string> hello world </string>
    	</key>
    	<value> <anytype xmlns:q1="http://www.w3.org/2001/XMLSchame" d4p1:type="q1:int"
    	xmlns:d4p1="http-instance">45</anytype>
    	</value>
      </item>
    </dictionary>
    and this is my code:
    Code:
    ########################################
    string path = "D:\\myXmlFile.xml";
    DataSet oDs = new DataSet();
    oDs.ReadXml(path);
    GridView1.DataSource = oDs;
    GridView1.DataBind();
    thanks
    Tom
    Last edited by Niheel; May 24 '10, 06:55 AM. Reason: code tags
  • ThatThatGuy
    Recognized Expert Contributor
    • Jul 2009
    • 453

    #2
    That XML wouldn't work..
    It's not organized as required
    The Xml required should be in form of Columns and their values some thing like this...

    [CODE=xml]
    <DataSet>
    <TableName>
    <Col1>CellData1 <Col1>
    <Col2>CellData2 <Col2>
    <Col3>CellData3 <Col3>
    </TableName>
    <TableName>
    <Col1>CellData1 <Col1>
    <Col2>CellData2 <Col2>
    <Col3>CellData3 <Col3>
    </TableName>
    </DataSet>
    [/CODE]

    Comment

    • Curtis Rutland
      Recognized Expert Specialist
      • Apr 2008
      • 3264

      #3


      Read that whole page, and you should find what you need.

      Comment

      Working...