C#實(shí)現(xiàn)DataList里面嵌套DataList的折疊菜單
本文實(shí)例講述了C#實(shí)現(xiàn)DataList里面嵌套DataList的折疊菜單。分享給大家供大家參考,具體如下:
點(diǎn)擊前效果圖如下:
點(diǎn)擊后效果圖如下:
具體實(shí)現(xiàn)代碼如下:
Javascript腳本
<script type="text/javascript"> function showmenu(id) { smallimg = eval("smallimg"+id); img =eval("img"+id); if(smallimg.style.display =="none") { eval("smallimg"+id+".style.display=\"\";");//全部顯示 img.src="Image/tree_folder3.gif";//顯示為- } else { eval("smallimg"+id+".style.display=\"none\";"); //全部隱藏 img.src="Image/tree_folder4.gif";//顯示為+ } } </script>
HTML代碼如下:
<body> <form id="Form1" method="post" runat="server"> <font face="宋體"></font> <table width="679" height="100%" border="0" cellpadding="0" cellspacing="0" align="center"> <tr> <td align="center" valign="top"> <strong>版塊 設(shè) 置</strong> <br /> <br /> 管理選項(xiàng):<asp:Button ID="btnAdd" runat="server" OnClick="btnAdd_Click" Text="添加一級(jí)版塊"/><br /> <br /> <asp:DataList ID="DataList1" runat="server" CellSpacing="0" CellPadding="0" Width="679" OnItemDataBound="DataList1_ItemDataBound"> <HeaderTemplate> <table width="679" border="0" cellpadding="0" cellspacing="0" bgcolor="#000000" class="border"> <tr bgcolor="#a4b6d7" class="title"> <td height="25" align="center"> <strong>版塊名稱</strong></td> <td height="20" align="center"> <strong>操作選項(xiàng)</strong></td> </tr> </HeaderTemplate> <ItemTemplate> <tr bgcolor="ECF5FF" class="tdbg"> <td height="22" width="50%"> <img id="img<%#Eval("BigClassID")%>" src="Image/tree_folder4.gif" width="15" height="15" onclick="showmenu(<%#Eval("BigClassID")%>)"><%#Eval("BigClassName")%></td> <td align="center" width="50%"> <a href='SmallClassAdd.aspx?BigClassID=<%#Eval("BigClassID")%>'> 添加二級(jí)版塊</a> | <a href='BigClassModify.aspx?BigClassID=<%#Eval("BigClassID")%>'> 修改一級(jí)版塊</a> | <a href='BigClassDelete.aspx?BigClassID=<%#Eval("BigClassID")%>' onclick="return confirm('確定刪除嗎,下級(jí)版塊及相關(guān)帖子都將被刪除,且不可恢復(fù)!!!')">刪除一級(jí)版塊</a></td> </tr> <tr bgcolor="ECF5FF" class="tdbg" width="100%"> <td colspan="2" width="100%"> <asp:DataList ID='dlstSmallClass' EnableViewState='false' runat='server'> <HeaderTemplate> <table width="679" border="0" cellpadding="0" cellspacing="0" bgcolor="#000000" class="border"> </HeaderTemplate> <ItemTemplate> <tr id="smallimg<%#Eval("BigClassID")%>" style="display:none" bgcolor="#E3E3E3" class="tdbg"> <td height="22" width="50%" colspan="3"> <img src="Image/tree_folder3.gif" width="15" height="15"><%#Eval("SmallClassName")%></td> <td align="center" width="50%" colspan="3"> <a href='SmallClassModify.aspx?SmallClassID=<%#Eval("SmallClassID")%>'> 修改二級(jí)版塊</a> | <a href='SmallClassDelete.aspx?SmallClassID=<%#Eval("SmallClassID")%>' onclick="return confirm('確定刪除嗎,相關(guān)帖子都將被刪除,且不可恢復(fù)!!!')">刪除二級(jí)版塊</a></td> </tr> </ItemTemplate> <FooterTemplate> </table> </FooterTemplate> </asp:DataList> </td> </tr> </ItemTemplate> <FooterTemplate> </table> </FooterTemplate> </asp:DataList> </td> </tr> </table> </form> </body>
上面的功能有點(diǎn)缺陷(ques1:多行時(shí)候不能折疊,默認(rèn)只折疊第一行;ques2:不支持IE),現(xiàn)在改善如下:
<script type="text/javascript"> function showmenu(id) { var smallimg = document.getElementById("smallimg"+id); var img = document.getElementById("img"+id); if(smallimg.style.display =="none") { smallimg.style.display=""; img.src="Image/tree_folder3.gif";//顯示為- } else { smallimg.style.display ="none"; img.src="Image/tree_folder4.gif";//顯示為+ } } </script>
<body> <form id="Form1" method="post" runat="server"> <font face="宋體"></font> <table width="679" height="100%" border="0" cellpadding="0" cellspacing="0" align="center"> <tr> <td align="center" valign="top"> <strong>版 塊 設(shè) 置</strong> <br /> <br /> 管理選項(xiàng):<asp:Button ID="btnAdd" runat="server" OnClick="btnAdd_Click" Text="添加一級(jí)版塊"/><br /> <br /> <asp:DataList ID="DataList1" runat="server" CellSpacing="0" CellPadding="0" Width="679" OnItemDataBound="DataList1_ItemDataBound"> <HeaderTemplate> <table width="679" border="0" cellpadding="0" cellspacing="0" bgcolor="#000000"class="border"> <tr bgcolor="#a4b6d7"class="title"> <td height="25" align="center"> <strong>版塊名稱</strong> </td> <td height="20" align="center"> <strong>操作選項(xiàng)</strong> </td> </tr> </HeaderTemplate> <ItemTemplate> <tr bgcolor="ECF5FF"class="tdbg"> <td height="22" width="50%"> <img id="img<%#Eval("BigClassID")%>" src="Image/tree_folder4.gif" width="15" height="15" onclick="showmenu(<%#Eval("BigClassID")%>)"><%#Eval("BigC <td align="center" width="50%" colspan="3"> <a href='SmallClassModify.aspx?SmallClassID=<%#Eval("SmallClassID")%>'> 修改二級(jí)版塊</a>|<a href='SmallClassDelete.aspx?SmallClassID=<%#Eval("SmallClassID")%>' onclick="return confirm('確定刪除嗎,相關(guān)帖子都將被刪除,且不可恢復(fù)!!!')">刪除二級(jí)版塊</a> </td> </tr> </ItemTemplate> <FooterTemplate> </table> </FooterTemplate> </asp:DataList> </td> </tr> </ItemTemplate> <FooterTemplate> </table> </FooterTemplate> </asp:DataList> </td> </tr> </table> </form> </body>
希望本文所述對(duì)大家C#程序設(shè)計(jì)有所幫助。
- C#實(shí)現(xiàn)基于XML配置MenuStrip菜單的方法
- C#自定義控件添加右鍵菜單的方法
- Android仿微信菜單(Menu)(使用C#和Java分別實(shí)現(xiàn))
- C#設(shè)置右鍵菜單的方法
- C#使用XML序列化操作菜單的方法
- C#遞歸讀取XML菜單數(shù)據(jù)的方法
- 基于C#實(shí)現(xiàn)的仿windows左側(cè)伸縮菜單效果
- 使用c#開(kāi)發(fā)公眾平臺(tái)自定義菜單功能
- c# winform讀取xml文件創(chuàng)建菜單的代碼
- c# TreeView添加右鍵快鍵菜單有兩種方法
- asp.net(C#)生成無(wú)限級(jí)別菜單
相關(guān)文章
C#公眾號(hào)開(kāi)發(fā)之給用戶發(fā)紅包
這篇文章主要為大家詳細(xì)介紹了C#公眾號(hào)開(kāi)發(fā)之給用戶發(fā)紅包,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-08-08C#配置文件Section節(jié)點(diǎn)處理總結(jié)
這篇文章主要介紹了C#配置文件Section節(jié)點(diǎn)處理總結(jié),針對(duì)配置文件Section節(jié)點(diǎn)的處理做了較為詳細(xì)的實(shí)例總結(jié),需要的朋友可以參考下2014-10-10用c#獲得當(dāng)前用戶的Application Data文件夾位置
用c#獲得當(dāng)前用戶的Application Data文件夾位置...2007-03-03DataGridView清除顯示的數(shù)據(jù)、設(shè)定右鍵菜單
這篇文章介紹了DataGridView清除顯示的數(shù)據(jù)、設(shè)定右鍵菜單的方法,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-02-02C# WinForm窗體編程中處理數(shù)字的正確操作方法
這篇文章主要介紹了C# WinForm窗體編程中處理數(shù)字的正確操作方法,本文給出了正確示例,并解釋了為什么要這么做,需要的朋友可以參考下2014-08-0812306奇葩驗(yàn)證碼引發(fā)思考之C#實(shí)現(xiàn)驗(yàn)證碼程序
春運(yùn)最高峰來(lái)了!明天通過(guò)網(wǎng)絡(luò)將能買到小年夜的車票,本周四就將開(kāi)售除夕日車票,但不少人被首次在春運(yùn)期間使用的圖片驗(yàn)證碼搞得很火大,小編也正在對(duì)驗(yàn)證碼進(jìn)行研究,編寫(xiě)了由C#實(shí)現(xiàn)驗(yàn)證碼程序,分享給大家2015-12-12C#中的lock、Monitor、Mutex學(xué)習(xí)筆記
這篇文章主要介紹了C#中的lock、Monitor、Mutex學(xué)習(xí)筆記,本文講解的都是線程同步的一些知識(shí),需要的朋友可以參考下2015-01-01C#數(shù)據(jù)結(jié)構(gòu)之雙向鏈表(DbLinkList)實(shí)例詳解
這篇文章主要介紹了C#數(shù)據(jù)結(jié)構(gòu)之雙向鏈表(DbLinkList),結(jié)合實(shí)例形式較為詳細(xì)的講解了雙向鏈表的概念及C#實(shí)現(xiàn)雙向鏈表的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-11-11