Refer this code
HTML
<form id="form1" runat="server">
<div>
<asp:Repeater ID="rptMenu" runat="server">
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<li><a href='<%# Eval("MenuLink") %>'>
<%# Eval("MenuText") %></a></li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
</div>
</form>
Namespaces
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.PopulateMenu();
}
}
private void PopulateMenu()
{
string constr = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT * FROM tblMenus", con))
{
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
DataTable dt = new DataTable();
da.Fill(dt);
this.rptMenu.DataSource = dt;
this.rptMenu.DataBind();
}
}
}
}
SQL
CREATE TABLE [dbo].[tblMenus](
[MenuId] [int] NOT NULL,
[MenuText] [varchar](100) NULL,
[MenuLink] [nvarchar](100) NULL
) ON [PRIMARY]
GO
----------------------
INSERT INTO [tblMenus]
([MenuId]
,[MenuText]
,[MenuLink])
VALUES
(1
,'Home'
,'Home.aspx')
GO
INSERT INTO [tblMenus]
([MenuId]
,[MenuText]
,[MenuLink])
VALUES
(2
,'About'
,'About.aspx')
GO
INSERT INTO [tblMenus]
([MenuId]
,[MenuText]
,[MenuLink])
VALUES
(3
,'Contact'
,'Contact.aspx')
Screenshot
