如何将<li>添加到<ui>并从后面的代码中将<ui>添加到新的</ui> </ui> </li> <li>

时间:2017-01-15 18:42:39

标签: c# html asp.net

如何向ui添加新的 li 并将ui添加到新的 li 我有一个html菜单,我需要从代码后面传递值到HTML 例如:

< ui> < li>from code < ui> from code < li>from code Sub menu < /li> < /ui> < /li> < /ui>

我的html代码:从后面的代码中读取值                    

  • 菜单                            
  • 子菜单
  •                                 

    我的C#代码//两个功能

    private void GetMenuData()
        {
            DataSet table = new DataSet();
            string strCon = System.Configuration.ConfigurationManager.ConnectionStrings["Test"].ConnectionString;
            SqlConnection conn = new SqlConnection(strCon);
            string sql = @"SELECT 'p' + .... etc";
            SqlCommand cmd = new SqlCommand(sql, conn);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(table);
            DataView view = new DataView(table.Tables[0]);
            view.RowFilter = "pID is NULL";
            foreach (DataRowView row in view)
            {
                if (!row["url"].ToString().Contains("AdminPage"))
                {
                    MenuItem menuItem = new MenuItem(row["name"].ToString(), row["ID"].ToString());
    
                    HtmlGenericControl li = new HtmlGenericControl("li");
                    tabs.Controls.Add(li);
                    HtmlGenericControl anchor = new HtmlGenericControl("a");
                    anchor.Attributes.Add("href",row["url"].ToString());
                    anchor.InnerText = row["name"].ToString();
                    HtmlGenericControl ui = new HtmlGenericControl("ui");
                    li.Controls.Add(anchor);
                    li.Controls.Add(ui);
    
                    AddChildItems(table.Tables[0], menuItem, ui);
                }
            }
        }
    private void AddChildItems(DataTable table, MenuItem menuItem,HtmlGenericControl ui)
        {
    
            DataView view = new DataView(table);
            DataView viewItem = new DataView(table);
            viewItem.RowFilter = "pID=" + menuItem.Value;
            foreach (DataRowView childView in viewItem)
            {
    
                HtmlGenericControl li = new HtmlGenericControl("li");
                ui.Controls.Add(li);
                HtmlGenericControl anchor = new HtmlGenericControl("a");
                anchor.Attributes.Add("href", childView["url"].ToString());
                anchor.InnerText = childView["name"].ToString();
                li.Controls.Add(anchor);
            }
        }
    

    0 个答案:

    没有答案