下面要说的这个方法,是我刚弄的。标题一个个累加,根据[去除HTML标记]的长度[字节数],大于指定长度,就换行。效果虽然实现,但总觉得不是很好。希望有更好的实现方法的朋友不吝赐教。
1<style type="text/css">
2body {}{
3 background-color: #FFF;
4 color: #000;
5 font-family: Tahoma, sans-serif;
6 font-size: 12px;
7 text-align: center;
8 margin: 0;
9 padding: 0;
10}
11a:link {}{
12 color: #000;
13 text-decoration: none;
14}
15a:visited {}{
16 color: #000;
17 text-decoration: none;
18}
19a:hover {}{
20 color: #F00;
21 text-decoration: underline;
22}
23a:active {}{
24 color: #000;
25 text-decoration: none;
26}
27div {}{ overflow: hidden; text-align:left}
28
29.CenterColumn {}{
30 float: left;
31 353px !important;
32 351px;
33}
34dl, dd {}{
35 clear: both;
36 margin: 0;
37 padding: 0;
38}
39dt {}{
40 background-position: top left;
41 background-repeat: no-repeat;
42}
43</style>
44<div>
45 <div class="CenterColumn" id="List" runat="server">
46 用来存放列表
47 </div>
48 </div>
1private string getList(DataTable dt)
2 {
3 string strResult = "<dl id=\"TopMsgs\"><dt>";
4 string strTemp = "";
5 foreach (DataRow dr in dt.Rows)
6 {
7 if (System.Text.Encoding.Default.GetByteCount(StripHTML(strTemp + dr[1].ToString())) > 80)//超过长度,换行在加
8 {
9 strResult += strTemp + "<br>";
10 strTemp = "<a href=\"http://www.lxqq.cn\">" + dr[1].ToString() + "</a>" + " ";
11 }
12 else
13 {
14 strTemp += "<a href=\"http://www.lxqq.cn\">"+dr[1].ToString()+"</a>"+" " ;
15 }
16 }
17 return strResult+strTemp+"</dt></dl>";
18 }
19/**////<summary>
20 /// 去除html标记
21 ///</summary>
22 ///<param name="strHtml">包括HTML的源码</param>
23 ///<returns>已经去除后的文字</returns>
24 private string StripHTML(string strHtml)
25 {
26 string temp = System.Text.RegularExpressions.Regex.Replace(strHtml, "<[^>]*>", "");
27 return temp;
28 }