This is a migrated thread and some comments may be shown as answers.

(ShowMenuItems)This constraint cannot be enabled as not all values have corresponding parent values.

5 Answers 230 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Jiten
Top achievements
Rank 1
Jiten asked on 02 Aug 2014, 12:46 PM
I have create method in master page and bind in radmenu control:
Here is the Code  that I get the table from session and bind
 
public void ShowMenuItems()
    {
        try
        {
            if (common.myStr(Session["MenuData"]) != "")
            {
                DataTable ds = (DataTable)Session["MenuData"];
                if (ds != null)
                {
                    if (ds.Rows.Count > 0)
                    {
                        for (int ii = 0; ii < ds.Rows.Count; ii++)
                        {
                            if (common.myInt(ds.Rows[ii]["ParentId"]) == 0)
                            {
                                ds.Rows[ii]["ParentId"] = DBNull.Value;
                                ds.AcceptChanges();
                            }
                        }
                        ds.DefaultView.Sort = "";
                        ds.DefaultView.RowFilter = "ModuleId =" + common.myInt(Session["ModuleId"]);
                        ds.DefaultView.Sort = "Sequence Asc";

                        if (ds.DefaultView.Count > 0)
                        {
                            RadMenu1.DataSource = ds.DefaultView;
                            //Establish hierarchy:
                            RadMenu1.DataFieldID = "PageId";
                            RadMenu1.DataFieldParentID = "ParentId";

                            //Set Text, Value, and NavigateUrl:  
                            RadMenu1.DataTextField = "PageName";
                            RadMenu1.DataValueField = "PageId";
                            RadMenu1.DataNavigateUrlField = "PageUrl";
                            RadMenu1.DataBind();
                        }
                    }
                }
            }
        }
        catch (Exception Ex)
        {
            objException.HandleExceptionWithMethod(Ex, "ShowMenuItems");
        }
    }
And following Error Occur in ourt database exception log table

(ShowMenuItems)This constraint cannot be enabled as not all values have corresponding parent values.
Please why this error come

Please help me I am helpless

Thanks


5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 04 Aug 2014, 09:26 AM
Hi Jiten,

This error will happen if the Parent value is not bind properly. Can you please check  if the root items have null values in their ParentId filed in database. The ParentId value has to be null for all the root items. Please provide your table structure and full code if it doesn't help.

Thanks,
Princy.
0
Sandeep
Top achievements
Rank 1
answered on 15 Oct 2014, 08:50 PM
I am getting the same error with treeview on databind please help

 private void BindToDataTable(RadTreeView treeView)
        {
            SqlConnection connection = new SqlConnection("Data Source=.;Initial Catalog=project;Integrated Security= True");
            SqlDataAdapter adapter = new SqlDataAdapter("SELECT id,Name,case when ParentID=NULL then Null else ParentID end as ParentID FROM Test", connection);
            DataTable dataTable = new DataTable();

            adapter.Fill(dataTable);
            treeView.DataTextField = "Name";
            treeView.DataFieldID = "id";
            treeView.DataValueField = "Description";
            treeView.DataFieldParentID = "ParentID";
            treeView.DataSource = dataTable;
            treeView.DataBind();
        }


ascx code

  <p>
        &nbsp;</p>
    <p>
        &nbsp;</p>
    <p>
        <telerik:RadTreeView ID="RadTreeView1" Runat="server" DataFieldID="id"
            DataFieldParentID="ParentID">

             <DataBindings>
                    <telerik:RadTreeNodeBinding Expanded="True"></telerik:RadTreeNodeBinding>
                     </DataBindings>
        </telerik:RadTreeView>
    </p>
    <p>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
    </p>
    <p>


table structure

id    Name    Parent ID    Description
1      sandeep    NULL      sss
2      akshay      Null          aaa
3       aseem      1            d  ddd
0
Nencho
Telerik team
answered on 20 Oct 2014, 10:31 AM
Hello Sandeep,

I tried to replicate the described issue, but to no avail. This is why, I am sending you the sample page, I have tested with. You could give it a try at your end and inspect the behavior. Please make sure that the data, in the underlying data table in question is correct structured, in order to meet the needed criteria for the hierarchical binding.

In addition, I noticed in the provided code snippet that the script manager is placed below the controls, used on the page. I would suggest you to always place the script manage, on the top of the page, in order to ensure that all the scripts are correctly loaded before the controls on the page.

In addition, you may refer to the following forum thread, where more information and suggestion, regarding the SELECT query and the data structure is provided :

http://www.telerik.com/forums/treeview-bind-error-quot-this-constraint-cannot-be-enabled-as-not-all-values-have-corresponding-parent-values-quot

Find the sample attached.

Regards,
Nencho
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Madhavi
Top achievements
Rank 1
answered on 29 Oct 2015, 12:18 PM

I have create method in master page and bind in radmenu control:
Here is the Code:

 

 protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                BindToDataSet();
            }
        }

        private void BindToDataSet()
        {
            SqlDataAdapter adapter = new SqlDataAdapter("SELECT  Serial_No, ItemId, ItemName,Ref_No FROM ProductHierarchy",
                    ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

            DataSet links = new DataSet();

            adapter.Fill(links);
            
            RadMenu1.DataTextField = "ItemName";
            RadMenu1.DataValueField = "ItemId";
            RadMenu1.DataNavigateUrlField = "";
            RadMenu1.DataFieldID = "Serial_No";
            RadMenu1.DataFieldParentID = "Ref_No";
            
            

            RadMenu1.DataSource = links;
            RadMenu1.DataBind();
        }​

 

.aspx

 <telerik:RadMenu ID="RadMenu1" runat="server" Style="z-index: 2" EnableRoundedCorners="true"  EnableShadows="true">  <%-- Skin="MenuSkin" EnableEmbeddedSkins="false"--%>

</telerik:RadMenu>​

 

 

Table structure

Serial_No        ItemId      ItemName     Ref_No 

1                       1                ABC              NULL

2                          2            XYZ               NULL

3                          3             PQR               1

4                         5             abc1                3

 

 It does not work properly. only menu strip(Parent menus) was display. submenus are not displays. Is there any problem.. please help.

0
Nencho
Telerik team
answered on 03 Nov 2015, 11:25 AM
Hello Madhavi,

The Data structure and approach that you use seems to be correct. Please make sure that the data is correctly acquired from the underlying database. In addition, in the attachment you can find a simple example, base on the provided code snippet, which works properly, when static datasource is used.

Regards,
Nencho
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Menu
Asked by
Jiten
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Sandeep
Top achievements
Rank 1
Nencho
Telerik team
Madhavi
Top achievements
Rank 1
Share this question
or