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.
I figured it out on my own. I did the following:
wdMain.DataSource = ds2;
foreach (DataTable dt in ds2.Tables)
{
DataMenuItemBinding db = new DataMenuItemBinding();
db.DataMember = dt.TableName;
db.TextField = "NAME";
db.NavigateUrlFields = "URL";
wdMain.DataBindings.Add(db);
}
wdMain.DataBind();
This let me set the datatables up and bind them correctly. If anyone wants to see the code i used to turn the flat dataset into the hierarchical one, please let me know.
That's close, but the problem is that I need a way to declare the bindings in codebehind. My dataset is a collection of tables (about 8) that are a set of menus and submenus.
So in the example code you gave, imagine there is another table (dt3)
DataTable dt3 = new DataTable("SubData")
dt3.Columns.Add("sID", typeof(int));
dt3.Columns.Add("cID", typeof(int));
dt3.Columns.Add("sTexts", typeof(string));
dt3.Rows.Add(1,10,"About Our Company");
dt3.Rows.Add(2,10,"Email Us");
and so on. Actually, my data is structured that a parent table shows the initial menu and each "dropdown" on the menu is it's own table. (Easier to turn from a self-referencing table into a tree using recursive function).
I think if i can get the DataBindings set up in code, i can probably walk the dataset and set it up.
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();}
dt.Columns.Add(
"rID", typeof(int));
"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");
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]);
In the markup, I amjust defining the appropriate DataBindings:
I'm not intimate with the WHDS... only know enough about it to get a couple simple pages to bind.
Not sure how to do it in codebehind, but maybe if you place a DataSet control on the page, you'll be able to add that to the WHDS at design-time?
I didn't try to feed the dataset directly into WHDS... instead I placed a SQLDataSource control (in dataset mode) on the page, and then created a view off of that in WHDS. That way, I was able to use the schema tools to make sure everything wired up correctly.
I've always been a fan of constructing my datasets in codebehind because I feel like I've got more control over every call to the database. Sure wish there was better documentation on how to do that kind of thing.
Another option would be to skip databinding altogether and just loop through your dataset and add your nodes in code.
Do you know of any easy ways to convert a standard relational dataset to a WHDS? I tried reading the help files and there wasn't much help. Searching the WHDS forum for DataSet didn't yield any results either.