Asp. Net Method of Generating Table by Infinite Classification of Background Custom Output table
- 2021-07-21 08:12:10
- OfStack
In this paper, an example is given to describe the method of generating tables by infinite classification in Asp. Net. Share it for your reference, as follows:
Data structure monitor_group
monitor_grp_id monitor_grp_name parent_id level childCount orderby
[int, auto increment] [nvarchar, not null] [int, not null] [int, not null] [int, not null] [int, null]
1 Database Server 0 1 2
2 Application Server 0 1 2
3 System Server 0 1 0
4 WEB Server 1 2 0
5 Mail Server 1 2 0
6 Proxy Server 2 2 0
7 Ftp Server 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 description of
/// </summary>
///
namespace yihan
{
namespace Data
{
public class myDataBind
{
public myDataBind()
{
//
//TODO: Add constructor logic here
//
}
public static string GetTree_monitor_grp_id(DataTable dt, int parent_id, ref string returnString)
{
// Bind directory tree
//dt:DataTable Object ;parent_id: Father ID;returnString: Output reference variable ;
DataRow[] dr = dt.Select("parent_id=" + parent_id);
int currentLenght = 0; // Current number of times
foreach (DataRow row in dr)
{
string nodeImg = ""; // Node picture
string treeLineImg = ""; // Tree line
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++)
{
// Calculation treeLineImg
if (i == Convert.ToInt32(row["level"]))
{
if (currentLenght == dr.Length) // Judge whether the current number of times is the same as this time dr The total quantity is equal
{ treeLineImg += " Whatever "; }
else
{ treeLineImg += " ' "; }
}
else
{
treeLineImg += " The ";
}
}
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"] + "'> Add a subclass </a> ";
returnString += "<a href='class_modi.aspx?monitor_grp_id=" + row["monitor_grp_id"] + "'> Modify </a> ";
returnString += "<a href='class_del.aspx?monitor_grp_id=" + row["monitor_grp_id"] + "' onclick=\"javascript:{if(!confirm(' Are you sure you want to delete this class and its subclasses ?'))return false;}\"> Delete </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); // Call
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"> Monitor group name </th>
<th width="9%" bgcolor="#BAD8EF"> Level </th>
<th width="15%" bgcolor="#BAD8EF"> Total number of child nodes </th>
<th width="29%" bgcolor="#BAD8EF"> Operation </th>
</tr>
<tr>
<td colspan="5" style="padding-left:6px;background:#DBDBDB;"> Monitor group </td>
</tr>
<asp:Literal ID="Literal1" runat="server"></asp:Literal>
</table>
</form>
</body>
Handwritten Table
string s="<table>"
s+="<tr><td>";
s+= Variable value ;
s+="</td></tr></table>";
ResPonse.Write(s);
As for loops and other methods, they are constructed by themselves
Readers who are interested in asp.net can check the topics of this site: "Summary of File Operation Skills of asp.net", "Summary of Skills of asp.net ajax" and "Summary of Cache Operation Skills of asp. net".
I hope this paper is helpful to everyone's asp. net programming.