二三级下拉菜单

if (!Page.IsPostBack)
        {
            string sql = "select * from InfoType";
            DataTable dt = SqlHelp.ExecuteDataTable(sql);
            string js = "",ss = "";
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (dt.Rows[i]["parenttypeid"].ToString()=="")
                {
                    js=dt.Rows[i]["typeid"].ToString();
                    DropDownList1.Items.Insert(i, new ListItem(dt.Rows[i]["tyepname"].ToString(), ""));
                }
                else
                {
                    if (dt.Rows[i]["parenttypeid"].ToString()==js)
                    {
                         ss = "+";
                    }
                    else
                    {
                        ss = "++";
                    }
                    DropDownList1.Items.Insert(i, new ListItem(ss + dt.Rows[i]["tyepname"].ToString(), ""));
                }
            }
        }

 

 private void DLbinddata()
    {
        string sql = "select * from InfoType"; //查询信息类型 下拉列表绑定
        DataTable dt = SqlHelp.ExecuteDataTable(sql);
        string js = "", ss = "";
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            if (dt.Rows[i]["parenttypeid"].ToString() == "") //判断每一行parenttypeid=空的 
            {
                js = dt.Rows[i]["typeid"].ToString();//获取这个typeid

                DropDownList1.Items.Insert(i, new ListItem(dt.Rows[i]["tyepname"].ToString(), dt.Rows[i]["typeid"].ToString()));
            }
            else
            {
                if (dt.Rows[i]["parenttypeid"].ToString() == js) // 判断子级的父级id = 这个父级id
                {
                    ss = " ├";
                }
                else
                {
                    ss = "  ├";
                }
                DropDownList1.Items.Insert(i, new ListItem(ss + dt.Rows[i]["tyepname"].ToString(), dt.Rows[i]["typeid"].ToString()));
            }
        }
    }

 

posted @ 2017-11-16 17:20  enych  阅读(275)  评论(0编辑  收藏  举报