Hello.
I'm using 8.1, the UltraWebMenu control, and binding to abn XML Datasource.
The acutal menu items are stored in a database, which are returned as a DataSet, converted to XML and transformed to another XML doc and bound to the XmlDatasource object. Everything works fine.
The problem is refreshing the menu. Perodically the XmlDatasource is repopulated (refreshed) but the UltraWebMenu doesn't reflect the updated XML doc. Here's the code from the page that is hosting the UltraWebMenu (both the XmlDatasource and UltraWebMenu controls have their EnableViewState property set to False):
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Me.XmlDataSource1.Data = Application("MenuXML").ToString() ' This is the new XML doc retrieved from the database Me.XmlDataSource1.DataFile = "" Me.XmlDataSource1.XPath = "/root/item[@MenuName='MNUMASTERTOP']" Me.XmlDataSource1.DataBind()End Sub
End Class
Any ideas?
Thanks in advance,
Mike
Really weird, since I originally thought this is a bug in UltraWebMenu. Then I've tried the same with the built-in asp:menu with pretty much the same results (Menu1 is asp:menu):
protected void UltraWebMenu1_PreRender(object sender, EventArgs e) { UltraWebMenu1.Items.Clear(); UltraWebMenu1.DataSourceID = "XmlDataSource1"; UltraWebMenu1.DataBind(); Menu1.Items.Clear(); Menu1.DataSourceID = "XmlDataSource1"; Menu1.DataBind(); }
I'd say, this has something to do with XmlDataSource being a declarative datasource control and it does not play nicely with code-behind and the lifecycle of the page. UltraWebMenu does provide support for binding directly to related DataTables inside a DataSet, so if you have this structure, why not try binding directly to this DataSet using the UltraWebMenu1.DataSource property?
Thanks for responding Rumen.
I didn't know it could bind to a Datatable. If you select "New Data Source", the only two options available are Site Map and XML File.
How do I bind to a DataTable?
You can try something along the lines of:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Dim dataSet As New DataSet() Dim orders As New DataTable() orders.TableName = "Orders" orders.Columns.Add("ID") orders.Columns.Add("Name") orders.Rows.Add(New Object() {1, "Nike shoes"}) orders.Rows.Add(New Object() {2, "Adidas shoes"}) orders.Rows.Add(New Object() {3, "Puma shoes"}) Dim details As New DataTable() details.Columns.Add("ID") details.Columns.Add("ParentID") details.Columns.Add("Name") details.Rows.Add(New Object() {1, 1, "Air Jordan"}) details.Rows.Add(New Object() {2, 2, "Kevin Garnett"}) details.Rows.Add(New Object() {3, 3, "Brazil Football"}) dataSet.Tables.Add(orders) dataSet.Tables.Add(details) dataSet.Relations.Add("OrderDetails", orders.Columns("ID"), details.Columns("ParentID")) Me.UltraWebMenu1.Levels(0).RelationName = "OrderDetails" Me.UltraWebMenu1.Levels(0).ColumnName = "Name" Me.UltraWebMenu1.Levels(1).ColumnName = "Name" UltraWebMenu1.DataSource = dataSet.Tables("Orders").DefaultView UltraWebMenu1.DataBind() End Sub
You can then rebind the menu each time the DataSet changes.
Hope this helps.
when we change the database we want the ultrawebgrid should be refreshed.when we find after changing the dataset /datatable The problem is refreshing the menu. Perodically the XmlDatasource is repopulated (refreshed) but the UltraWebMenu doesn't reflect the updated XML doc.
The solution to this problem is please change the Xmldatasource property.EnableCaching = false.
Ok. Thanks Rumen.