C# 后台生成HTML table 传到前台页面

后台:

/// <summary>
        /// 2016年1月23日  动态加载首页
        /// </summary>
        /// <param name="spID"></param>
        /// <returns></returns>
        public string Menu()
        {
            string connStr = AppConfiguration.CoreConnectionString;
            string sql = @"select * from  MenuCode where MenuID in(SELECT A.RightID FROM CodeGroupRight A,OperatorRole B,RoleRight C 
WHERE A.CodeGroupID in(2001,2002,2003,2004,2005,2006,2007,2008
,2009,2010,2011,2012,2013,2014,2015,2016,2017) AND B.OperatorID = "+this.OpLoginInfo.OperatorID+" AND B.RoleID = C.RoleID AND A.RightID = C.RightID GROUP BY A.RightID,B.ApplicationTypeIDs) and vc2Type='sp' ";
            DataSet ds = SqlHelper.ExecuteDataset(connStr, CommandType.Text, sql);

            StringBuilder sb = new StringBuilder();
            sb.Append("<table id=\"table1\">\n");
            
            sb.Append("<tr><th></th><th></th></tr>\n");

            int trid = 11;
            int NextTrid = 21;

            int trid2 = 12;
            int NextTrid2 = 22;

            int count = ds.Tables[0].Rows.Count + 1; ;

            for (int i = 0; i <= ds.Tables[0].Rows.Count; i= i+2)
            {
                int j = 0;
                string name2 = string.Empty;
                string HtmlUrl2 = string.Empty;

                if (i < ds.Tables[0].Rows.Count)
                {
                    j = i + 1;
                    name2 = ds.Tables[0].Rows[i]["MenuName"].ToString();
                    HtmlUrl2 = ds.Tables[0].Rows[i]["vc2Url"].ToString();
                }

                

                

                string name = ds.Tables[0].Rows[j]["MenuName"].ToString();
                string HtmlUrl = ds.Tables[0].Rows[j]["vc2Url"].ToString();


                if (j == 0)
                {
                    sb.Append("<tr ><td  runat=\"server\" height=\"30\" width=\"27\" id=\"tr" + trid + "\"><IMG height=\"27\" src=\"images/list.gif\" width=\"27\"></td><td runat=\"server\" width=\"160\" align=\"left\" id=\"tr" + NextTrid + "\"><A class=\"boldtitle\" href=" + HtmlUrl + ">" + name + "</A></td> </tr>\n");
                }
                else
                {
                    sb.Append("<tr ><td  runat=\"server\" height=\"30\" width=\"27\" id=\"tr" + trid + "\"><IMG height=\"27\" src=\"images/list.gif\" width=\"27\"></td><td runat=\"server\" width=\"160\" align=\"left\" id=\"tr" + NextTrid + "\"><A class=\"boldtitle\" href=" + HtmlUrl + ">" + name + "</A></td> <td  runat=\"server\" height=\"30\" width=\"27\" id=\"tr" + trid2 + "\"><IMG height=\"27\" src=\"images/list.gif\" width=\"27\"></td><td runat=\"server\" width=\"160\" align=\"left\" id=\"tr" + NextTrid2 + "\"><A class=\"boldtitle\" href=" + HtmlUrl2 + ">" + name2 + "</A></td></tr>\n");
                }
                trid = trid + 2;
                NextTrid = NextTrid + 2;

                trid2 = trid2 + 2;
                NextTrid2 = NextTrid2 + 2;
            }
          

            sb.Append("</table >\n");
            return sb.ToString();
        }

前台:  

<%=Menu()%>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值