国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

Asp.Net實(shí)現(xiàn)無限分類生成表格的方法(后臺(tái)自定義輸出table)

2024-07-10 13:30:17
字體:
供稿:網(wǎng)友
這篇文章主要介紹了Asp.Net實(shí)現(xiàn)無限分類生成表格的方法,同時(shí)后臺(tái)自定義輸出table表格,詳細(xì)分析了asp.net生成表格的相關(guān)技巧,需要的朋友可以參考下
 

本文實(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)教程知識(shí)閱讀請(qǐng)移步到ASP.NET教程頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 得荣县| 镇赉县| 海口市| 红原县| 根河市| 乌兰察布市| 锡林浩特市| 肥城市| 许昌市| 江西省| 尼勒克县| 苏尼特左旗| 襄城县| 株洲县| 清原| 巴林左旗| 奇台县| 车险| 台中市| 山阳县| 江华| 凌云县| 婺源县| 乌兰浩特市| 丹阳市| 阿图什市| 广南县| 来安县| 阿拉善右旗| 山西省| 依安县| 玛纳斯县| 双峰县| 美姑县| 宁德市| 赣榆县| 昂仁县| 新兴县| 恩施市| 青阳县| 津南区|