Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
430
Problem with WHDG
posted

Hi everyone,

This is my first time that I work with the WHDG. So I would like to bind my WHDG to xml.

I realize the first step "Loading the "title" tag in the table, but when I click into the arrow to display the sub items, an error will appear saying:

Key:Category must be unique. The field objects in the grid must have non-empty unique keys assigned to the Key property.

this is My XML File:

<?xml version="1.0" encoding="utf-8"?>
<ItemList>
<Item><Category>1- category 1</Category><Title>title 11</Title><Key>A1</Key></Item>
<Item><Category>1- category 1</Category><Title>title 12</Title><Key>A2</Key></Item>
<Item><Category>1- category 1</Category><Title>title 13</Title><Key>A3</Key></Item>
<Item><Category>1- category 1</Category><Title>title 14</Title><Key>A4</Key></Item>
<Item><Category>2- category 2</Category><Title>title 21</Title><Key>A5</Key></Item>
<Item><Category>2- category 2</Category><Title>title 22</Title><Key>A6</Key></Item>
<Item><Category>2- category 2</Category><Title>title 23</Title><Key>A7</Key></Item>
<Item><Category>2- category 2</Category><Title>title 24</Title><Key>A8</Key></Item>
<Item><Category>3- category 3</Category><Title>title 31</Title><Key>A9</Key></Item>
<Item><Category>3- category 3</Category><Title>title 32</Title><Key>A10</Key></Item>
<Item><Category>3- category 3</Category><Title>title 33</Title><Key>A11</Key></Item>
<Item><Category>4- category 4</Category><Title>title 41</Title><Key>A12</Key></Item>
<Item><Category>4- category 4</Category><Title>title 42</Title><Key>A13</Key></Item>
<Item><Category>4- category 4</Category><Title>title 43</Title><Key>A14</Key></Item>
<Item><Category>4- category 4</Category><Title>title 44</Title><Key>A15</Key></Item>
<Item><Category>4- category 4</Category><Title>title 45</Title><Key>A16</Key></Item>
<Item><Category>4- category 4</Category><Title>title 46</Title><Key>A17</Key></Item>
</ItemList>
this my code ASP
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
    <center>
    <h1>Infragistics WebHierarchicalDataGrid bound to on-the-fly grouped data</h1>
    <h2>Uses on-demand loading of child records</h2>
        <ig:WebHierarchicalDataGrid id="WebHierarchicalDataGrid1" runat="server"
           Width="800px" AutoGenerateBands="False" AutoGenerateColumns="False" 
            EnableAjax="False">
        </ig:WebHierarchicalDataGrid>
    
    </center>
    </div>
    </form>
</body>
</html>

and finally here is my C# Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;
using Infragistics.Web.UI.GridControls;

namespace HierarchicalGrid
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {

                DataSet dsModele = new DataSet();
                dsModele.ReadXml(@"C:\ModeleFR.pmml");
                dsModele.Tables[0].TableName = "Model";

                DataView dv = dsModele.Tables["Model"].DefaultView;
                dv.Sort = "Category ASC";
                dsModele.Tables.Add(dv.ToTable("Categories", true, "Category"));

                DataRelation rel = new DataRelation("CategoryModel",
                    dsModele.Tables["Categories"].Columns["Category"],
                    dsModele.Tables["Model"].Columns["Category"]);
                dsModele.Relations.Add(rel);

                dsModele.Tables["Categories"].PrimaryKey = new DataColumn[] { 
                    dsModele.Tables["Categories"].Columns["Category"] };

                this.Session["CategoryModel"] = dsModele;
            }

            DataSet ds = this.Session["CategoryModel"] as DataSet;

            
            BoundDataField boundField = new BoundDataField(true);
            boundField.Key = "Category";
            boundField.Header.Text = "Category";
            boundField.DataFieldName = "Category";
            this.WebHierarchicalDataGrid1.Columns.Add(boundField);

            Band childBand = new Band();
            childBand.DataKeyFields = "Title";

            childBand.Key = "Categories1";
            childBand.DataMember = "Categories";

            this.WebHierarchicalDataGrid1.Bands.Add(childBand);

            boundField = new BoundDataField(true);
            boundField.Key = "Title";
            boundField.Header.Text = "Title";
            boundField.DataFieldName = "Title";

            this.WebHierarchicalDataGrid1.Bands["Categories1"].Columns.Add(boundField);



            this.WebHierarchicalDataGrid1.DataSource = ds;
            this.WebHierarchicalDataGrid1.DataMember = "Categories";
            this.WebHierarchicalDataGrid1.DataKeyFields = "Category";
            this.WebHierarchicalDataGrid1.DataBind();
        }
    }
}
Anyone can help me please
THANK YOU

 

Parents Reply Children
No Data