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
435
Bind to a Standard Dataset with Relations?
posted

I have my menu data coming back in a DataSet with Relations created between the tables.  All the sample code i can find shows how to bind the WebDataMenu with a WebHierarchicalDataSource.  Is there any way to bind to just a regular DataSet with Relations?  I tried setting the DataSource to the DataSet, but all that gets me is a bunch of "Infragistics.Web.UI.Framework.Data.DataSetNode" objects on the menu with no way of showing children.

 

 

Parents
No Data
Reply
  • 4493
    Suggested Answer
    posted

    Hello,

    It is easily supported, you just have to set the correct DataMenuItemBinding settings in your markup, and then Bind the WebDataMenu to the DataSet in the Code Behind.

    Please take a look at the attached sample page.

    Here is what it does:
    In the CodeBehind file I am just create a DataSet with two tables and relation between them! It is important to notice that, in order for databinding to works, you ought to have Primary Key defined for every table in your data set:

    protected void Page_Load(object sender, EventArgs e)
    {
    this.wdMain.DataSource = GetData();
    this.wdMain.DataBind();
    }

     

     

     

    protected DataSet GetData()
    {

     

     

     

    DataSet ds = new DataSet("menuData");

     

     

     

    DataTable dt = new DataTable("RootData");

    dt.Columns.Add(

     

    "rID", typeof(int));

    dt.Columns.Add(

     

    "rTexts", typeof(string));

    dt.PrimaryKey =

     

    new DataColumn[1] { dt.Columns[0] };

    dt.Rows.Add(1,

     

    "File");

    dt.Rows.Add(2,

     

    "Edit");

    dt.Rows.Add(3,

     

    "Help");

     

     

     

     

    DataTable dt2 = new DataTable("ChildData");
    dt2.Columns.Add(
    "cID", typeof(int));
    dt2.Columns.Add(
    "rID", typeof(int));

    dt2.Columns.Add(

     

    "cTexts", typeof(string));
    dt2.PrimaryKey =
    new DataColumn[1] { dt2.Columns[0] };

    dt2.Rows.Add(1, 1,

     

    "Open");

    dt2.Rows.Add(2, 1,

     

    "Close");

    dt2.Rows.Add(3, 1,

     

    "Save");

    dt2.Rows.Add(4, 1,

     

    "Exit");

    dt2.Rows.Add(5, 2,

     

    "Cut");

    dt2.Rows.Add(6, 2,

     

    "Copy");

    dt2.Rows.Add(7, 2,

     

    "Paste");

    dt2.Rows.Add(8, 2,

     

    "Find");

    dt2.Rows.Add(9, 3,

     

    "About");

    dt2.Rows.Add(10,3,

     

    "General Help");

    ds.Tables.Add(dt);

    ds.Tables.Add(dt2);

    ds.Relations.Add(dt.Columns[0], dt2.Columns[1]);

     

     

     

    return ds;

     

     

    In the markup, I amjust defining the appropriate DataBindings:

     

     

     

     

     

     

     

     

    <ig:WebDataMenu runat="server" ID="wdMain">

     

     

     

    <DataBindings>

     

     

     

    <ig:DataMenuItemBinding DataMember="RootData" TextField="rTexts" />

     

     

     

    <ig:DataMenuItemBinding DataMember="ChildData" TextField="cTexts" />

     

     

     

    </DataBindings>

     

     

     

    </ig:WebDataMenu>

    WebDataMenuDataSetBinding.zip
Children