Skip to content

Instantly share code, notes, and snippets.

@meyu
Created April 3, 2018 08:24
Show Gist options
  • Save meyu/08478c72e5df75c59e4a4873c70c3a19 to your computer and use it in GitHub Desktop.
Save meyu/08478c72e5df75c59e4a4873c70c3a19 to your computer and use it in GitHub Desktop.
sample of making a bootstrap navbar-like-html at asp.net in vb.net
Public Class a_Struct
'系統資訊設定
Public ReadOnly SystemTitle As String = "滿意不滿意系統"
Public ReadOnly helpBuss As String() = {"業務諮詢", "1111", "林林林老師"} '業務承辦人資訊
Public ReadOnly helpTech As String() = {"系統維護", "8888", "李李李先生"} '系統管理者資訊
Public ReadOnly menuLeft As String(,) = {{"問卷填寫", "Home.aspx"}} '使用者選單
Public ReadOnly menuRight As String(,) = {{"問卷管理", "Admin.aspx"}} '管理者選單
'生成選單 (採用 Bootstrap Navbar 元件)
Public Function getMenu() As String
UserInfo()
If 帳號 = "" Then
HttpContext.Current.Response.Redirect(pageLogout)
End If
'標頭
Dim site_info_header = "<div id=""site_info_header""><div class=""container"">"
Dim logo_uch = "<div id=""logo_uch""></div>"
Dim site_title = "<div id=""site_title"">" + SystemTitle + "</div>"
Dim site_user_info = "<div id=""site_user_info"">"
Dim site_user_nameyou = "<div id=""site_user_nameyou""><i class=""far fa-id-card fa-fw""></i><span>" + 姓名 + "</span></div>"
Dim site_user_contact = "<div id=""site_user_contact"" data-toggle=""modal"" data-target=""#contact_modal""></div>"
Dim site_user_signout = "<div id=""site_user_signout"" onclick='if (confirm(""確定要登出?"")) {window.open(""" + pageLogout + """,""_self"");}'></div>"
site_user_info += site_user_nameyou + site_user_contact + site_user_signout + "</div>"
site_info_header += logo_uch + site_title + site_user_info + "</div></div>"
'選單
Dim scarf = "<nav id=""scarf"" class=""navbar navbar-expand-md navbar-dark""><div class=""container"">"
Dim navbarbrand = "<span Class=""navbar-brand"" href=""#"">" + SystemTitle + "</span>"
Dim navbartoggler = "<button type=""button"" Class=""navbar-toggler"" data-toggle=""collapse"" data-target=""#barbar""><span Class=""navbar-toggler-icon""></span></button>"
'項目群
Dim barbar = "<div class=""collapse navbar-collapse"" id=""barbar""><ul class=""navbar-nav mr-auto"">"
Dim navitem = ""
'一般使用者項目
If menuLeft.GetLength(0) > 0 Then
For n As Integer = 0 To menuLeft.GetLength(0) - 1
navitem += "<li Class=""nav-item""><a Class=""nav-link"" href=""" + menuLeft(n, 1) + """>" + menuLeft(n, 0) + "</a></li>"
Next
End If
'管理者項目
If isAdmin Then
If menuRight.GetLength(0) > 0 Then
For n As Integer = 0 To menuRight.GetLength(0) - 1
navitem += "<li Class=""nav-item""><a Class=""nav-link"" href=""" + menuRight(n, 1) + """>" + menuRight(n, 0) + "</a></li>"
Next
End If
End If
barbar += navitem + "</ul></div>"
scarf += navbarbrand + navbartoggler + barbar + "</div></nav>"
Dim contact_modal = "<div Class=""modal fade"" id=""contact_modal"" tabindex=""-1"" role=""dialog"" aria-hidden=""true""><div Class=""modal-dialog""><div Class=""modal-content modal-body"">"
contact_modal += "<ul Class=""list-group"">"
contact_modal += helpListGroup(helpBuss)
contact_modal += helpListGroup(helpTech)
contact_modal += "</ul></div></div></div>"
Return site_info_header + scarf + contact_modal
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment