My VB Code Starts Here
Private Function GetCategories() As DataTable
Dim strcon As String = ConfigurationManager.ConnectionStrings("KRGCbiz").ConnectionString
Dim connection As New SqlConnection(strcon)
Dim selectCommand As New SqlCommand("SELECT MenuId, Menus FROM MenusDetails", connection)
Dim dt As New DataTable()
Try
connection.Open()
Dim reader As SqlDataReader = selectCommand.ExecuteReader()
If reader.HasRows Then
dt.Load(reader)
End If
reader.Close()
Catch generatedExceptionName As SqlException
Throw
Finally
connection.Close()
End Try
Return dt
End Function
Private Function GetAllCategories() As DataTable
Dim strcon As String = ConfigurationManager.ConnectionStrings("KRGCbiz").ConnectionString
Dim connection As New SqlConnection(strcon)
Dim selectCommand As New SqlCommand("SELECT SubMenuId, SubMenu, MenuId, Menus FROM Submenus", connection)
Dim dt As New DataTable()
Try
connection.Open()
Dim reader As SqlDataReader = selectCommand.ExecuteReader()
If reader.HasRows Then
dt.Load(reader)
End If
reader.Close()
Catch generatedExceptionName As SqlException
Throw
Finally
connection.Close()
End Try
Return dt
End Function
Protected Sub rptCategories_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptCategories.ItemDataBound
If True Then
If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then
If allCategories IsNot Nothing Then
Dim sb As New StringBuilder()
Dim drv As DataRowView = TryCast(e.Item.DataItem, DataRowView)
Dim ID As String = drv("MenuId").ToString()
Dim Menu As String = drv("Menus").ToString()
Dim rows As DataRow() = allCategories.[Select](Convert.ToString("MenuId=") & ID, "Menus")
If Menu = "Home" Then
//drv("Menus").Attributes.Add("onclick", "return Home();")
End If
If rows.Length > 0 Then
sb.Append("<ul>")
For Each item As DataRow In rows
sb.Append("<li><a href='#' >" + item("SubMenu") + "</a></li>")
Next
sb.Append("</ul>")
TryCast(e.Item.FindControl("ltrlSubMenu"), Literal).Text = sb.ToString()
End If
End If
End If
End If
End Sub
My ASPX Page Structure
<asp:repeater ID="rptCategories" runat="server" OnItemDataBound="rptCategories_ItemDataBound">
<headertemplate>
<div class="menu"><ul>
</headertemplate>
<itemtemplate>
<li>
<a href='#'> <%#Eval("Menus")%></a>
<asp:literal ID="ltrlSubMenu" runat="server"></asp:literal>
</li>
</itemtemplate>
<footertemplate>
</ul></div>
</footertemplate>
</asp:repeater>
To redirect to another page when the menu is clicked, I have JavaScript like this:
<script type="text/javascript">
function alertMe() {
alert("License");
window.location.replace('SoftwareLicenseDetails.aspx');
return false;
}
function Home() {
alert("Home");
window.location.replace('SystemDetails.aspx');
return false;
}
</script>
If you click on "Home", it should redirect you to another page. How can this be achieved? I've been trying for the past few days but haven't found a solution that meets my requirements. Can someone help me out? Thank you in advance!