System.Text.StringBuilder拼装table

来源:互联网 发布:比邻协议软件 编辑:程序博客网 时间:2024/04/29 08:41

//建立业务层对象
   SooF.BusinessRules.Apeak.BRSchools brSchool =new SooF.BusinessRules.Apeak.BRSchools(); 
   
   DataSet ds = brSchool.SingleShoolsDataSet(Province);

   if((ds.Tables.Count>0)&&(ds.Tables[0].Rows.Count>0))
   {
    iCount = ds.Tables[0].Rows.Count; 
    this.LabelCount.Text = iCount.ToString() ;
   }

   System.Text.StringBuilder mystr=new System.Text.StringBuilder();
   
   dt = ds.Tables[0];
   string BgColor = "";
   if(iCount>0)
   {
    mystr.Append(@"<TABLE cellSpacing=""0"" cellPadding=""0"" width=""100%"" border=""0""><tr><td>" + "/n");
    foreach(DataRow myRow in dt.Rows)
    {
     string id="ShowSchool.aspx?ID="+myRow["id"].ToString();
     mystr.AppendFormat(@"<tr" + BgColor + @"><td width=""25%"" height=""25"">·<a href=""{0}"" class=""lan_01"" target=""_blank"">",id);
     mystr.Append(@myRow["Name"].ToString());
     mystr.Append(@"</a></div></td>");
     mystr.Append(@"<td width=""21%""><div align=""center"" class=""hui_01"">");
     mystr.Append(@myRow["Kind"].ToString());
     mystr.Append(@"</div></td>");

     mystr.Append(@"<td width=""30%"" class=""hui_01"" nowrap><div align=""center"">");
     mystr.Append(@Convert.ToDateTime(myRow["PutTime"].ToString()).ToShortDateString());
     mystr.Append(@"</div></td>");
     string message = "AddSchoolMessage.aspx?ID="+myRow["id"].ToString();
                    mystr.Append(@"<td width=""24%"" class=""hui_01"" ><div align=""center"">");
     mystr.AppendFormat(@"<a href=""{0}"" class=""lan_01"" target=""_blank"">",message);
     mystr.Append(@messageText);
     mystr.Append(@"</a></div></td></tr>");
     if (BgColor == "")
     {
      BgColor = " bgcolor=/"#F5F5F5/"";
     }
     else
     {
      BgColor = "";
     }
    }
    mystr.Append("</table>");

   }
   this.show.Text=mystr.ToString();