2017-06-18 72 views
0

我有一個樹形視圖格式類型的側面導航菜單。我面臨的問題是側面導航欄應該適應數據庫中的數據。我寫了下面的代碼。動態菜單數據

private void GetMenuData() 
{ 
    DataTable table = new DataTable(); 
    string cs = System.Configuration.ConfigurationManager.ConnectionStrings["myconectionstring"].ConnectionString; 
    SqlConnection conn = new SqlConnection(cs); 
    string sql = "select SiteName from SiteMaster"; 
    SqlCommand cmd = new SqlCommand(sql, conn); 
    SqlDataAdapter da = new SqlDataAdapter(cmd); 
    da.Fill(table); 
    DataView view = new DataView(table); 
    foreach (DataRowView row in view) 
    { 
    sites.InnerHtml= Server.HtmlDecode("<li><a href='#'><i class='fa fa-circle-o text-warning'></i>" + row["SiteName"].ToString() + "</a></li>"); 
    } 
} 

SiteMaster表包含SiteName列表。這裏的問題是隻有最後一個SiteName被顯示在側面菜單中。我希望顯示SiteName列下的所有行。

網站是ID爲<ul>

+0

你需要因此它的可讀性格式化你的代碼! – Matt

+0

我很抱歉,我只是從VS複製粘貼。 – pratheek

回答

0

給你的代碼看起來應該像

sites.InnerHtml += Server.HtmlDecode ... 

,而不是

sites.InnerHtml = Server.HtmlDecode ... 
+0

超。非常感謝你。那解決了我的問題.... – pratheek

+0

不客氣。 – IngoB