2 Answers, 1 is accepted
0
Kevin Babcock
Top achievements
Rank 1
answered on 14 Jul 2008, 12:21 AM
Hello Ranganath,
Here is an example of connecting to the database (in this case, Northwind) and creating dynamic RadMenuItems to add to a RadMenu. Keep in mind that this is just a simple example and you would want to use your own data access classes to retrieve relevant data from your tables.
I hope this example helps.
Sincerely,
Kevin Babcock
Here is an example of connecting to the database (in this case, Northwind) and creating dynamic RadMenuItems to add to a RadMenu. Keep in mind that this is just a simple example and you would want to use your own data access classes to retrieve relevant data from your tables.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DynamicRadMenu.aspx.cs" Inherits="DynamicRadMenu" %> | |
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> | |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head runat="server"> | |
<title>Untitled Page</title> | |
</head> | |
<body> | |
<form id="form1" runat="server"> | |
<telerik:RadScriptManager ID="RadScriptManager1" runat="server" /> | |
<telerik:RadMenu ID="RadMenu1" runat="server" /> | |
</form> | |
</body> | |
</html> | |
using System; | |
using System.Data; | |
using System.Data.SqlClient; | |
public partial class DynamicRadMenu : System.Web.UI.Page | |
{ | |
protected void Page_Load(object sender, EventArgs e) | |
{ | |
var dataTable = this.GetData(); | |
foreach (DataRow row in dataTable.Rows) | |
{ | |
var companyName = Convert.ToString(row["CompanyName"]); | |
var navigateUrl = String.Format("http://www.someurl.com/customers?id={0}", Convert.ToString(row["CustomerID"])); | |
var menuItem = new Telerik.Web.UI.RadMenuItem(companyName, navigateUrl); | |
RadMenu1.Items.Add(menuItem); | |
} | |
} | |
private DataTable GetData() | |
{ | |
var data = new DataTable(); | |
using (SqlConnection con = new SqlConnection("Data Source=.\\SQLSERVER;Initial Catalog=Northwind;User ID=sa;Password=*******")) | |
{ | |
var sql = "SELECT TOP 5 [CompanyName], [CustomerID] FROM [Customers];"; | |
using (SqlCommand cmd = new SqlCommand(sql, con)) | |
{ | |
cmd.CommandType = CommandType.Text; | |
SqlDataAdapter adapter = new SqlDataAdapter(cmd); | |
try | |
{ | |
// Retrieve the records | |
adapter.Fill(data); | |
} | |
catch (SqlException e) { } | |
} | |
} | |
return data; | |
} | |
} | |
I hope this example helps.
Sincerely,
Kevin Babcock
0
Hi Ranganath,
In addition, you can download and watch the RadMenu for ASP.NET AJAX – Data Binding episode of our training tutorial.
Kind regards,
Veskoni
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
In addition, you can download and watch the RadMenu for ASP.NET AJAX – Data Binding episode of our training tutorial.
Kind regards,
Veskoni
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center