iSeller Commerce
iSeller POS Retail
iSeller POS F&B
iSeller POS Express
Crosslight
WebUI
ClientUI
What's New
Download Trial
Web Solution
Mobile Solution
Enterprise Solution
Custom Development
Blog
Community
Latest Development Blogs
ForumPostTopic
Browse By Tag
I need to fill one bar Collection with a short list of items from a database list. Any ideas?
Hi Ben,
Basically, if we want to use a SQL Server Connection, we can simply set the return value as a DataTable. After we get the data in DataTable format, we can get the total count of rows and get the value of its row(we can also get by its column as well). Here is the snippet to do so:
WebNavPane navPane = (WebNavPane)WebPaneManager1.FindControl("WebNavPane1");
DataTable dt = new DataTable(); string connString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Northwind.mdf;Integrated Security=True;User Instance=True"; SqlConnection conn = new SqlConnection(connString); SqlDataAdapter daCustomers = new SqlDataAdapter(); conn.Open(); string queryCustomers = "SELECT * FROM Categories"; SqlCommand cmd = new SqlCommand(queryCustomers, conn); daCustomers.SelectCommand = cmd; daCustomers.Fill(dt); int index = dt.Rows.Count; for (int i = 0; i < index; i++) { WebNavBar[] navBar = new WebNavBar[index]; WebNavBarItem[] navBarItem = new WebNavBarItem[index]; navBar[i] = new WebNavBar(); navBarItem[i] = new WebNavBarItem(); navBarItem[i].Name = dt.Rows[i].ItemArray[2].ToString(); navBarItem[i].Text = dt.Rows[i].ItemArray[2].ToString(); navBarItem[i].DisplayMode = ISNet.WebUI.WebDesktop.DisplayMode.Text; navBar[i].Name = dt.Rows[i].ItemArray[1].ToString(); navBar[i].Text = dt.Rows[i].ItemArray[1].ToString(); navBar[i].CaptionDisplayMode = ISNet.WebUI.WebDesktop.DisplayMode.Text; navBar[i].Items.Add(navBarItem[i]); navPane.Bars.Add(navBar[i]); }
I hope it helps. Thank you and have a nice day.
Best Regards,
Andi Santoso
Hi Ben Denison,
In order to do so, since we need to create an object of NavBar and NavBarItem for each data that we have got from the database list, we will need to use an arrayed of NavBar and NavBarItem object. During the looping, we can add each NavBarItem to NavBar and then, add them to our NavPane one by one.
Here is the snippet to do so:
protected void Page_Load(object sender, EventArgs e) { WebNavPane navPane = (WebNavPane)WebPaneManager1.FindControl("WebNavPane1"); List<SimpleList.Customer> cust = SimpleList.CustomerManager.GetCustomer(); int index = cust.Count; for (int i = 0; i < index; i++) { WebNavBar[] navBar = new WebNavBar[index]; WebNavBarItem[] navBarItem = new WebNavBarItem[index]; navBar[i] = new WebNavBar(); navBarItem[i] = new WebNavBarItem(); navBarItem[i].Name = cust[i].CustomerName; navBarItem[i].Text = cust[i].CustomerName; navBarItem[i].DisplayMode = ISNet.WebUI.WebDesktop.DisplayMode.Text; navBar[i].Name = cust[i].CustomerID.ToString(); navBar[i].Text = cust[i].CustomerID.ToString(); navBar[i].CaptionDisplayMode = ISNet.WebUI.WebDesktop.DisplayMode.Text; navBar[i].Items.Add(navBarItem[i]); navPane.Bars.Add(navBar[i]); } }
I also attached you my running sample along with the database list(SimpleList.cs). Please ensure to put this .cs file into the App_Code folder in your project.
That's great, thanks. I just need to change the data source to a SQL Server connection and I'll be set. Are there any quick examples around?
or
Choose this if you're already a member of Intersoft Community Forum. You can link your OpenID account to your existing Intersoft Social ID.
Choose this if you don't have an Intersoft account yet. Your authenticated OpenID will be automatically linked to your new Intersoft account.
Enter your Wordpress Blogname