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

[Solved] RadMenu from xml and dataset

1 Answer 178 Views
Menu
This is a migrated thread and some comments may be shown as answers.
wnl
Top achievements
Rank 1
wnl asked on 18 Jun 2009, 01:21 PM
Hi,
I want to build RadMenu from an xml file and a dataset (xsd).
So I load my xml file into dataset.
Xml file:
<?xml version="1.0" encoding="utf-8"?>  
<MenuConfig xmlns="http://tempuri.org/MenuConfig.xsd">  
   <MenuDT> 
    <Id>1</Id>      
    <Text>House</Text> 
    <URL>URL1</URL> 
    <CnfgId>1</CnfgId> 
    <ParentId>null</ParentId> 
  </MenuDT> 
  <MenuDT> 
    <Id>2</Id>      
    <Text>Cars</Text> 
    <URL>URL2</URL> 
    <CnfgId>1</CnfgId> 
    <ParentId>1</ParentId> 
  </MenuDT> 
</MenuConfig> 
and:
MenuConfig menu = new MenuConfig();//dataset  

 

 


menu.ReadXml(MapPath(
"App_Code/MenuConfig.xml"), System.Data.XmlReadMode.IgnoreSchema);  
 
RadMenu1.DataSource = menu.Tables["MenuDT"];  
//Establish hierarchy:  
RadMenu1.DataFieldID = "Id";  
RadMenu1.DataFieldParentID = "ParentId";  
//Set Text, Value, and NavigateUrl:  
RadMenu1.DataTextField = "Text";  
RadMenu1.DataValueField = "Id";  
RadMenu1.DataNavigateUrlField = "URL";  
RadMenu1.DataBind(); 

And I have an error: This constraint cannot be enabled as not all values have corresponding parent values.

I think that ParentId column in xml (set to null) isn't null in c#, it's a normal string.
Is that any solutions to avoid this? At now I change ParentId (in xml) to 0 and set null in c# code (I think that it's not a good idea) :
for (int ii = 0; ii < menu.Tables["MenuDT"].Rows.Count; ii++)  
        {  
            if (Convert.ToInt32((menu.Tables["MenuDT"].Rows[ii]["ParentId"])) == 0)  
            {  
                menu.Tables["MenuDT"].Rows[ii]["ParentId"] = null;  
                menu.Tables["MenuDT"].AcceptChanges();  
            }  
        } 

ParentId column in code of xsd file:
 <xs:element name="ParentId" msprop:Generator_UserColumnName="ParentId" 
msprop:
nullValue="_null" msprop:Generator_ColumnVarNameInTable="columnParentId" 
msprop:
Generator_ColumnPropNameInTable="ParentIdColumn" 
msprop:
Generator_ColumnPropNameInRow="ParentId" type="xs:string" minOccurs="0" /> 
Any ideas how to proper make it?

1 Answer, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 22 Jun 2009, 01:32 PM
Hi Jaromin Sycz,

Have you tried setting the nillable="true" ?
If it does not help - please send us a sample running project demonstrating the problem. We will debug it locally and find a working solution.

Kind regards,
Veselin Vasilev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Menu
Asked by
wnl
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Share this question
or