zoukankan      html  css  js  c++  java
  • ASP.NET

    下拉列表--------

    数据库设计:

    -- 无限分类 --
    
    -- 数据库:DB_InfiniteCategory
    
    -- 数据表:Tb_Infinite
    
    ---------------------------------------------------------------
    
    -- 创建数据库
    CREATE DATABASE DB_InfiniteCategory
    
    -- 创建数据表
    USE DB_InfiniteCategory
    CREATE TABLE Tb_Infinite
    (
        id int not null,                        --逻辑主键
        pid int not null,                        --父级
        categoryName varchar(10) not null        --分类名称
    )
    
    
    --使用语句
    select id, pid, categoryName from Tb_Infinite where pid = 0

    代码:

     1 using System;
     2 using System.Web.UI;
     3 using System.Data;
     4 using System.Data.SqlClient;
     5 
     6 using DAL;
     7 using System.Web.UI.WebControls;
     8 
     9 namespace InfiniteCategory
    10 {
    11     public partial class Default : System.Web.UI.Page
    12     {
    13         string toadd = "";
    14 
    15         protected void Page_Load(object sender, EventArgs e)
    16         {
    17             if (!Page.IsPostBack)
    18             {
    19                 GetArticleCategory("0");
    20             }
    21         }
    22 
    23         public void GetArticleCategory(string pid)
    24         {
    25             SqlConnection conn = new SqlConnection(" server = HUANGFU-PC; database = DB_InfiniteCategory; integrated security = true");
    26             string sql = "select id,categoryName from Tb_Infinite where pid=@pid";
    27             SqlCommand cmd = new SqlCommand(sql, conn);
    28             SqlParameter Pid = new SqlParameter("@pid", SqlDbType.Int);
    29             Pid.Value = pid;
    30             cmd.Parameters.Add(Pid);
    31             conn.Open();
    32             SqlDataReader sdr = cmd.ExecuteReader();
    33             while (sdr.Read())
    34             {
    35                 this.DropDownList1.Items.Add(new ListItem(toadd + " " + sdr[1].ToString(), sdr[0].ToString()));
    36                 toadd += "─┴";
    37                 this.GetArticleCategory(sdr[0].ToString());
    38                 toadd = toadd.Substring(0, toadd.Length - 2);
    39             }
    40             sdr.Close();
    41             conn.Close();
    42         }
    43     }
    44 }

    最终效果:

    ===============================================================

    导航--------

    代码:

     1 using System;
     2 using System.Web.UI;
     3 using System.Data;
     4 using System.Data.SqlClient;
     5 using System.Text;
     6 
     7 using DAL;
     8 using System.Web.UI.WebControls;
     9 
    10 namespace InfiniteCategory
    11 {
    12     public partial class Default : System.Web.UI.Page
    13     {
    14         StringBuilder s = new StringBuilder();
    15 
    16         protected void Page_Load(object sender, EventArgs e)
    17         {
    18             if (!Page.IsPostBack)
    19             {
    20                 GetArticleCategory("16");
    21             }
    22         }
    23 
    24         public void GetArticleCategory(string id)
    25         {
    26             SqlConnection conn = new SqlConnection(" server = HUANGFU-PC; database = DB_InfiniteCategory; integrated security = true");
    27             string sql = "select id,pid,categoryName from Tb_Infinite where id=@id";
    28             SqlCommand cmd = new SqlCommand(sql, conn);
    29             SqlParameter Pid = new SqlParameter("@id", SqlDbType.Int);
    30             Pid.Value = id;
    31             cmd.Parameters.Add(Pid);
    32             conn.Open();
    33             SqlDataReader sdr = cmd.ExecuteReader();
    34             while (sdr.Read())
    35             {
    36                 s.Append(sdr[2].ToString()+">");
    37                 this.GetArticleCategory(sdr[1].ToString());
    38             }
    39             this.Label1.Text = s.ToString();
    40             sdr.Close();
    41             conn.Close();
    42         }
    43     }
    44 }

    最终效果:

  • 相关阅读:
    iOS 文本展开收起
    iOS 图片拉伸压缩展示对比
    iOS 视图在最前显示的两种实现方式对比
    iOS UITableView上滑吸顶的三种方案
    iOS UITableView在 UITableViewStyleGrouped样式下第一组组头变高问题
    友盟统计 实时统计使用
    RN 侧滑删除功能实现
    RN 使用Radio实现单选
    RN 使用Checkbox实现多选
    iOS开发加密
  • 原文地址:https://www.cnblogs.com/KTblog/p/4638557.html
Copyright © 2011-2022 走看看