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>版塊名稱(chēng)</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>版塊名稱(chēng)</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#教程
下一篇:輕松學(xué)習(xí)C#的基礎(chǔ)入門(mén)
本文標(biāo)題:C#實(shí)現(xiàn)DataList里面嵌套DataList的折疊菜單
本文地址:http://mengdiqiu.com.cn/a1/C_jiaocheng/6845.html
您可能感興趣的文章
- 01-10C#實(shí)現(xiàn)txt定位指定行完整實(shí)例
- 01-10WinForm實(shí)現(xiàn)仿視頻 器左下角滾動(dòng)新聞效果的方法
- 01-10C#實(shí)現(xiàn)清空回收站的方法
- 01-10C#實(shí)現(xiàn)讀取注冊(cè)表監(jiān)控當(dāng)前操作系統(tǒng)已安裝軟件變化的方法
- 01-10C#實(shí)現(xiàn)多線(xiàn)程下載文件的方法
- 01-10C#實(shí)現(xiàn)Winform中打開(kāi)網(wǎng)頁(yè)頁(yè)面的方法
- 01-10C#實(shí)現(xiàn)遠(yuǎn)程關(guān)閉計(jì)算機(jī)或重啟計(jì)算機(jī)的方法
- 01-10C#自定義簽名章實(shí)現(xiàn)方法
- 01-10C#文件斷點(diǎn)續(xù)傳實(shí)現(xiàn)方法
- 01-10winform實(shí)現(xiàn)創(chuàng)建最前端窗體的方法


閱讀排行
- 1C語(yǔ)言 while語(yǔ)句的用法詳解
- 2java 實(shí)現(xiàn)簡(jiǎn)單圣誕樹(shù)的示例代碼(圣誕
- 3利用C語(yǔ)言實(shí)現(xiàn)“百馬百擔(dān)”問(wèn)題方法
- 4C語(yǔ)言中計(jì)算正弦的相關(guān)函數(shù)總結(jié)
- 5c語(yǔ)言計(jì)算三角形面積代碼
- 6什么是 WSH(腳本宿主)的詳細(xì)解釋
- 7C++ 中隨機(jī)函數(shù)random函數(shù)的使用方法
- 8正則表達(dá)式匹配各種特殊字符
- 9C語(yǔ)言十進(jìn)制轉(zhuǎn)二進(jìn)制代碼實(shí)例
- 10C語(yǔ)言查找數(shù)組里數(shù)字重復(fù)次數(shù)的方法
本欄相關(guān)
- 01-10C#通過(guò)反射獲取當(dāng)前工程中所有窗體并
- 01-10關(guān)于ASP網(wǎng)頁(yè)無(wú)法打開(kāi)的解決方案
- 01-10WinForm限制窗體不能移到屏幕外的方法
- 01-10WinForm繪制圓角的方法
- 01-10C#實(shí)現(xiàn)txt定位指定行完整實(shí)例
- 01-10WinForm實(shí)現(xiàn)仿視頻 器左下角滾動(dòng)新
- 01-10C#停止線(xiàn)程的方法
- 01-10C#實(shí)現(xiàn)清空回收站的方法
- 01-10C#通過(guò)重寫(xiě)Panel改變邊框顏色與寬度的
- 01-10C#實(shí)現(xiàn)讀取注冊(cè)表監(jiān)控當(dāng)前操作系統(tǒng)已
隨機(jī)閱讀
- 08-05dedecms(織夢(mèng))副欄目數(shù)量限制代碼修改
- 01-10SublimeText編譯C開(kāi)發(fā)環(huán)境設(shè)置
- 01-11ajax實(shí)現(xiàn)頁(yè)面的局部加載
- 04-02jquery與jsp,用jquery
- 01-10C#中split用法實(shí)例總結(jié)
- 01-10delphi制作wav文件的方法
- 08-05DEDE織夢(mèng)data目錄下的sessions文件夾有什
- 01-10使用C語(yǔ)言求解撲克牌的順子及n個(gè)骰子
- 01-11Mac OSX 打開(kāi)原生自帶讀寫(xiě)NTFS功能(圖文
- 08-05織夢(mèng)dedecms什么時(shí)候用欄目交叉功能?