This is a mirror of official site: http://jasper-net.blogspot.com/

Populating the TreeView Control With XMLDataSource

| Monday, September 12, 2011
The TreeView is a .NET DataBound Control which is used to display hierarchical data. It can be bound with the The Nodes of this control with the help of XML, tabular or Relational Data. In this example we use XMLDataSouce to bind the TreeView.

XMLDataSouce implements the IHierarchicalDataSouce interface. It simply sets the DataSourceId property of the TreeView Control to the ID value of the data source control and the TreeView Control automatically binds to the specified data source Control.

The TreeView Control Contains a DataBindings property that is a collection of TreeNodeBinding objects that define the binding between a DataItem and a TreeNode.

Here I write a simple program to show the binding of XMLDataSource and Treeview.

Step 1: First we create a XML File.(in my case XMLFile.xml)

File :-> New :-> File :-> XML File

Step 2: Write the following code in it.

<?xml version="1.0" encoding="utf-8" ?>
<Customers>
  <Customer CustomerId="1" Name="Mahak">
    <Orders>
      <Order OrderId="1" ShipDate="06-09-2011">
        <OrderItems>
          <OrderItem OrderItemId="1" PartNumber="123" PartDesc="Large" Quantity="5" Price="22.00"></OrderItem>
          <OrderItem OrderItemId="2" PartNumber="1234" PartDesc="Small" Quantity="6" Price="99.00"></OrderItem>
        </OrderItems>
      
      </Order>
      <Order OrderId="2" ShipDate="09-12-2011">
        <OrderItems>
          <OrderItem OrderItemId="3" PartNumber="153" PartDesc="Medium" Quantity="7" Price="232.00"></OrderItem>
          <OrderItem OrderItemId="4" PartNumber="1236" PartDesc="Half" Quantity="8" Price="299.00"></OrderItem>
        </OrderItems>

      </Order>

    </Orders>
    <Invoices>
      <Invoice InvoiceId="5" Amount="99.23" />
      <Invoice InvoiceId="6" Amount="88.89" />
    </Invoices>

  </Customer>
  <Customer CustomerId="2" Name="Neha">
    <Orders>
      <Order OrderId="3" ShipDate="08-09-2011">
        <OrderItems>
          <OrderItem OrderItemId="11" PartNumber="1223" PartDesc="Large" Quantity="52" Price="22.00"></OrderItem>
          <OrderItem OrderItemId="22" PartNumber="12134" PartDesc="Small" Quantity="62" Price="99.00"></OrderItem>
        </OrderItems>


Read more: C# Corner
QR: https://chart.googleapis.com/chart?chs=80x80&cht=qr&choe=UTF-8&chl=http://www.c-sharpcorner.com/UploadFile/mahakgupta/9203/

Posted via email from Jasper-net

0 comments: