This is the behind code from the "BuildMenu" example for data binding for ASPxMenu:
public partial class _Default : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
BuildMenu(ASPxMenu1, AccessDataSource1, false);
}
protected void BuildMenu(ASPxMenu menu, SqlDataSource dataSource, bool enableRoles) {
// Get DataView
DataSourceSelectArguments arg = new DataSourceSelectArguments();
DataView dataView = dataSource.Select(arg) as DataView;
dataView.Sort = "ParentID";
// Build Menu Items
Dictionary<string, DevExpress.Web.ASPxMenu.MenuItem> menuItems =
new Dictionary<string, DevExpress.Web.ASPxMenu.MenuItem>();
for (int i = 0; i < dataView.Count; i++) {
DataRow row = dataView
.Row;
if (!enableRoles || IsAccessible(row)) {
DevExpress.Web.ASPxMenu.MenuItem item = CreateMenuItem(row);
string itemID = row["ID"].ToString();
string parentID = row["ParentID"].ToString();
if (menuItems.ContainsKey(parentID))
menuItems[parentID].Items.Add(item);
else {
if (parentID == "0") // It's Root Item
menu.Items.Add(item);
}
menuItems.Add(itemID, item);
}
}
}
private DevExpress.Web.ASPxMenu.MenuItem CreateMenuItem(DataRow row) {
DevExpress.Web.ASPxMenu.MenuItem ret = new DevExpress.Web.ASPxMenu.MenuItem();
ret.Text = row["Text"].ToString();
ret.NavigateUrl = row["NavigateUrl"].ToString();
ret.Image.Url = row["ImageUrl"].ToString();
return ret;
}
// Security
private bool IsAccessible(DataRow row) {
string[ roles = GetRoles(row["Roles"].ToString());
return IsInRole(roles);
}
private bool IsInRole(string[ roles) {
foreach (string role in roles) {
if ((role == "*") || ((HttpContext.Current.User != null) && HttpContext.Current.User.IsInRole(role)))
return true;
}
return false;
}
private string[ GetRoles(string rolesString) {
List<string> ret = new List<string>();
foreach (string roleString in rolesString.Split(' ')) {
string curRoleStr = roleString.Trim();
if (curRoleStr.Length > 0)
ret.Add(curRoleStr);
}
return ret.ToArray();
}
}
I want to "translate" this C# to VB
Thank you a lot.