zoukankan
html css js c++ java
动态生成静态菜单
很轻易的实现静态菜单。
首先,需要定义div容器,并且定义ID标识,最重要的是加入runat="server"属性,这样div就能在后台代码中进行操作。
例如:
<
div
id
="sysFolders"
runat
="server"
align
="center"
>
</
div
>
后台操作如下:
First:
定义静态的链接栏模板。
Templet
private
const
string
folderTemplet
=
"
<div onMouseOver='MoveIn(this);' onMouseOut='MoveOut(this)' style='cursor:hand;170px;margin-top:8px; height:20px' ><img src='index_files/Pic/Button/21.gif' /><a href='Mail/DisplayMail.aspx?directoryID=parameter' target='main'>folderName</a></div>
"
;
Second:
从数据库读取所需信息,并套用静态的模板,生成一个个单独的模板对象。
Access Database
public
void
LoadSystemFolders()
{
Dictionary
<
int
,
string
>
dirs
=
new
Dictionary
<
int
,
string
>
();
dirs
=
DirectoryManager.getInstance().SysFolder;
string
folders
=
string
.Empty;
if
(dirs.Count
>
0
)
{
foreach
(KeyValuePair
<
int
,
string
>
item
in
dirs)
{
string
folder
=
string
.Empty;
folder
+=
folderTemplet;
folder
=
folder.Replace(
"
directoryID=parameter
"
,
"
directoryID=
"
+
item.Key.ToString());
folder
=
folder.Replace(
"
folderName
"
, item.Value.ToString());
folders
+=
folder;
}
sysFolders.InnerHtml
=
folders;
}
}
在这里特别说明下:
folder
=
folder.Replace(
"
directoryID=parameter
"
,
"
directoryID=
"
+
item.Key.ToString());
如果其其代码如下,
只是多了一个空格
,程序就不对啦,我当时不小心犯了这个错误,找了半天才找到,郁闷
folder
=
folder.Replace(
"
directoryID=parameter
"
,
"
directoryID =
"
+
item.Key.ToString());
Third:
将这些对象填入Div容器。
sysFolders.InnerHtml
=
folders;
查看全文
相关阅读:
最近半年
CentOS 6.4和Eclipse Juno CDT(4.2.2)的bug
cygwin/X XDMCP连接CentOS
手把手教你emacs cedet C/C++自动补全
ProFont – 识别度极高的终端字体
ACE之旅——环境搭建、HelloWorld
静态链表在优化中的应用
ACE之旅——第一个ACE通讯程序daytime
ThinkPHP 自定义标签测试 冰糖
FreeTextBox使用详解 (版本3.1.1)
原文地址:https://www.cnblogs.com/yank/p/1081107.html
最新文章
POJ 2362 Sqare【DFS】
POJ 3258 \poj 3273\poj 3122 【二分】
【转】图的点连通度边连通度总结
背包问题POJ 1252 Euro Efficiency【完全背包】
POJ 2676 Sudoku【DancingLinks,数独】
HDU 3473 Minimum Sum【划分树】
POJ 1681 Painter's Problem【状态压缩,枚举】
POJ 3067 Japan【一维树状数组】
背包问题POJ 3260 The Fewest Coins【完全背包+多重背包】
POJ 3740 Easy Finding【Dancinglinks】
热门文章
POJ 3281 Dining【Dinic】
TJU 3758. Jewel 【划分树,树状数组】
POJ 2449 Remmarguts' Date【K短路问题,A*、dijkstra】
POJ 1149 PIGS【SAP】
POJ 3414 Pots【BFS水】
背包问题POJ 1948 Triangular Pastures[二维01背包]
POJ 1961/POJ 2406 /POJ 2752 /【KMP应用】
POJ 2104 Kth Number【划分树】
POJ 1459 Power Network【SAP】
Linux下使用Fixedsys字体
Copyright © 2011-2022 走看看