ASP.net method of realizing infinite classification generation table (background custom output table) _ Practical Tips

Source: Internet
Author: User

The example of this paper describes the method of ASP.net to realize the infinite classification generation table. Share to everyone for your reference, specific as follows:

Data Structure Monitor_group

monitor_grp_id monitor_grp_name parent_id level ChildCount by
[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///</summary>///namespace Yihan {namespace Data {public class Myda Tabind {public Mydatabind () {////todo: Adding constructor logic//} public stat here IC string gettree_monitor_grp_id (DataTable dt, int parent_id, ref string returnstring) {//Binding directory tree//d
        T:datatable object; parent_id: Parent id;returnstring: output reference variable; datarow[] dr = dt.
        Select ("parent_id=" + parent_id);     int currentlenght = 0;    Current number of foreach (DataRow row in DR) {string nodeimg = "";  Node picture string treelineimg = "";
          Tree line Currentlenght + + 1; if (CoNvert.
          ToInt32 (row["ChildCount"]) > 0) {nodeimg = "\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 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 delete the 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 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" > sub-nodes Total </th> <th width= "
    29%" bgcolor= "#BAD8EF" > Operations </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>

Handwriting table

String s= "<table>"
s+= "<tr><td>";
s+= variable value;
s+= "</td></tr></table>";
Response.Write (s);

As for the cycle and its other methods to construct themselves

More interested in asp.net related content readers can view the site topics: "asp.net file Operation skills Summary", "ASP.net ajax Skills Summary" and "asp.net cache operation skills Summary."

I hope this article will help you to ASP.net program design.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.