Asp.Net實(shí)現(xiàn)無限分類生成表格的方法(后臺(tái)自定義輸出table)
本文實(shí)例講述了Asp.Net實(shí)現(xiàn)無限分類生成表格的方法。分享給大家供大家參考,具體如下:
數(shù)據(jù)結(jié)構(gòu) monitor_group
monitor_grp_id monitor_grp_name parent_id level childCount orderby
[int,自動(dòng)遞增] [nvarchar,not null] [int,not null] [int,not null] [int,not null] [int ,null]
1 數(shù)據(jù)庫服務(wù)器 0 1 2
2 應(yīng)用服務(wù)器 0 1 2
3 系統(tǒng)服務(wù)器 0 1 0
4 WEB服務(wù)器 1 2 0
5 郵件服務(wù)器 1 2 0
6 代理服務(wù)器 2 2 0
7 Ftp服務(wù)器 2 2 0
\App_code\data.cs
using System;
using System.Data;
using MySql.Data.MySqlClient;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
/// <summary>
///common 的摘要說明
/// </summary>
///
namespace yihan
{
namespace Data
{
public class myDataBind
{
public myDataBind()
{
//
//TODO: 在此處添加構(gòu)造函數(shù)邏輯
//
}
public static string GetTree_monitor_grp_id(DataTable dt, int parent_id, ref string returnString)
{
//綁定目錄樹
//dt:DataTable對(duì)象;parent_id:父ID;returnString:輸出引用變量;
DataRow[] dr = dt.Select("parent_id=" + parent_id);
int currentLenght = 0; //當(dāng)前次數(shù)
foreach (DataRow row in dr)
{
string nodeImg = ""; //節(jié)點(diǎn)圖片
string treeLineImg = ""; //樹線
currentLenght += 1;
if (Convert.ToInt32(row["childCount"]) > 0)
{nodeImg = "<img src='images/treeExpand.gif' align='absmiddle'>";}
else
{nodeImg = "<img src='images/treeNode.gif' align='absmiddle'>";}
for (var i = 1; i <= Convert.ToInt32(row["level"]); i++)
{
//計(jì)算treeLineImg
if (i == Convert.ToInt32(row["level"]))
{
if (currentLenght == dr.Length) //判斷當(dāng)前次數(shù)是否與本次dr總數(shù)量相等
{ treeLineImg += "└ "; }
else
{ treeLineImg += "├ "; }
}
else
{
treeLineImg += "│ ";
}
}
returnString += "<tr>\n";
returnString += "<td align='left'>" + treeLineImg + nodeImg + " " + row["monitor_grp_name"] + "</td>\n";
returnString += "<td align='center'>" + row["level"] + "</td>\n";
returnString += "<td align='center'>" + row["childCount"] + "</td>\n";
returnString += "<td align='center'>";
returnString += "<a href='class_add.aspx?monitor_grp_id=" + row["monitor_grp_id"] + "'>添加子類</a> ";
returnString += "<a href='class_modi.aspx?monitor_grp_id=" + row["monitor_grp_id"] + "'>修改</a> ";
returnString += "<a href='class_del.aspx?monitor_grp_id=" + row["monitor_grp_id"] + "' onclick=\"javascript:{if(!confirm('確刪要?jiǎng)h除該類及其子類嗎?'))return false;}\">刪除</a> ";
returnString += "</td>\n";
returnString += "</tr>\n";
GetTree_monitor_grp_id(dt, Convert.ToInt32(row["monitor_grp_id"]), ref returnString);
}
return returnString;
}//GetCatalogTree End
}//myDataBind End
}
}
class_list.aspx.cs
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using yihan.Data;
public partial class monitor_monitor_group_class_list : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dt = new DataTable();
string resultString = "";
string sql = "select * from monitor_group order by orderby desc,monitor_grp_id";
DbConn conn = new DbConn();
dt = conn.DataTable(sql);
Literal1.Text = myDataBind.GetTree_monitor_grp_id(dt, 0, ref resultString); //調(diào)用
dt.Dispose();
conn.Close();
}
}
}
class_list.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="class_list.aspx.cs" Inherits="monitor_monitor_group_class_list" %>
<body>
<form id="form1" runat="server">
<table class="conBox" width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#66AADD">
<tr align="center" bgcolor="#999999">
<th width="36%" bgcolor="#BAD8EF">監(jiān)視器組名稱</th>
<th width="9%" bgcolor="#BAD8EF">級(jí)別</th>
<th width="15%" bgcolor="#BAD8EF">子節(jié)點(diǎn)總數(shù)</th>
<th width="29%" bgcolor="#BAD8EF">操作</th>
</tr>
<tr>
<td colspan="5" style="padding-left:6px;background:#DBDBDB;">監(jiān)視器組</td>
</tr>
<asp:Literal ID="Literal1" runat="server"></asp:Literal>
</table>
</form>
</body>
手寫Table
string s="<table>" s+="<tr><td>"; s+=變量值; s+="</td></tr></table>"; ResPonse.Write(s);
至于循環(huán)及其其他的方法自己構(gòu)造
更多關(guān)于asp.net相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《asp.net文件操作技巧匯總》、《asp.net ajax技巧總結(jié)專題》及《asp.net緩存操作技巧總結(jié)》。
希望本文所述對(duì)大家asp.net程序設(shè)計(jì)有所幫助。
- asp.net多選項(xiàng)卡頁面的創(chuàng)建及使用方法
- iis6網(wǎng)站屬性沒有asp.net選項(xiàng)卡的解決辦法
- C#更改tabControl選項(xiàng)卡顏色的方法
- C#實(shí)現(xiàn)多選項(xiàng)卡的瀏覽器控件
- ASP.NET 中 Button、LinkButton和ImageButton 三種控件的使用詳解
- ASP.NET中訪問DataGrid中所有控件值的方法
- 支持Ajax跨域訪問ASP.NET Web Api 2(Cors)的示例教程
- ASP.NET 中ImageMap控件的用法
- ASP.NET中Label控件用法詳解
- ASP.NET中MultiView和View選項(xiàng)卡控件的使用方法
相關(guān)文章
asp.net IList查詢數(shù)據(jù)后格式化數(shù)據(jù)再綁定控件
這篇文章送給.net初學(xué)者或者遇到類似問題的朋友,就是IList如何格式化數(shù)據(jù)再綁定,我看到網(wǎng)上沒有多少朋友講到這方面的最基本的問題,現(xiàn)在我簡(jiǎn)單說說吧,代碼我就截取其中一些講,如果不明白的朋友可以留言或者聯(lián)系我。2009-11-11
gridview中實(shí)現(xiàn)radiobutton的單選示例
radiobutton可以單選,于是想讓gridview也可以實(shí)現(xiàn),具體的思路及代碼如下,感興趣的朋友可以參考下2013-08-08
asp.net中javascript的引用(直接引入和間接引入)
Asp.net 中引入Javascript的方法有很多,個(gè)人認(rèn)為可以分為直接引入,和間接引入,下面是兩種具體的引用方法,感興趣的朋友可以參考下哈2013-06-06
Visual Studio 2017如何用正則修改部分內(nèi)容詳解
這篇文章主要給大家介紹了關(guān)于Visual Studio 2017如何用正則修改部分內(nèi)容的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-05-05
ASP.NET Mvc開發(fā)之刪除修改數(shù)據(jù)
這篇文章主要介紹了ASP.NET Mvc開發(fā)中的刪除修改數(shù)據(jù)功能,感興趣的小伙伴們可以參考一下2016-03-03
.NET Core使用FluentEmail發(fā)送郵件的示例代碼
這篇文章主要介紹了.NET Core使用FluentEmail發(fā)送郵件的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-10-10
.NET之生成數(shù)據(jù)庫全流程實(shí)現(xiàn)
這篇文章主要介紹了.NET之生成數(shù)據(jù)庫全流程實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-05-05
ASP.NET框架中的數(shù)據(jù)綁定概要與數(shù)據(jù)綁定表達(dá)式的使用
數(shù)據(jù)綁定是ASP.NET中操作數(shù)據(jù)的基礎(chǔ)方式,這里我們暫時(shí)拋開.NET提供的控件,來從基礎(chǔ)上講解ASP.NET框架中的數(shù)據(jù)綁定概要與數(shù)據(jù)綁定表達(dá)式的使用:2016-06-06

