DataList中如何格式化字符串(页面显示评论内容显示)
2009-03-04 18:25
260 查看
1.后台 早就为datalist绑定了数据源
2.然后在后台还提供我刚才的那个截取方法
//格式化评论内容(格式化就用这个)
protected string Famart(string str)
{
int numId = 0; //定义行数
int wordsInRow = 20; //定义一行显示多少个字符
String returnStr = ""; //格式化之后的字符
//循环控制显示的内容及格式
for(int i = 0; i < Math.Ceiling(str.Length/(float)wordsInRow); i ++)
{
//控制每行显示的内容
if (str.Length - numId * wordsInRow >= wordsInRow)
returnStr += "行:<font color=red>" + (numId+1)+"</font>:"+str.Substring(numId * wordsInRow,wordsInRow) + "<BR>";
else
returnStr += "行:<font color=red>" + (numId+1) + "</font>:" + str.Substring(numId * wordsInRow, str.Length - numId * wordsInRow) + "<BR>";
numId++;
}
return returnStr;
}
//格式化评论内容(截取就用这个)
protected string Famart(string str)
{
if (str.Length > 6)
{
return str.Substring(0, 5) + "...";
}
else
{
return str;
}
}
3.最后在前台就以“<%# Famart(Eval("CommentText").ToString())%> ” 去调用 刚才这个方法(传入参数)
<asp:DataList ID="DlCommentMess" runat="server" Width="128%" DataKeyField="CommentID" RepeatColumns="2">
<ItemTemplate>
<table align="center" width="75%">
<tr>
<td align="left">
<%--调用方法--%>
<%# Famart(Eval("CommentText").ToString())%>
</td>
</tr>
<tr>
<td align="left">
网名:<%#Eval("CommentFromName")%><br />
E-mail:<%#Eval("CommentFromWebURL")%><br />
评论时间:<%#Eval("CommentDateSubmitted")%>
<hr color="#CCCCCC" noshade="noshade" size="2">
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
2.然后在后台还提供我刚才的那个截取方法
//格式化评论内容(格式化就用这个)
protected string Famart(string str)
{
int numId = 0; //定义行数
int wordsInRow = 20; //定义一行显示多少个字符
String returnStr = ""; //格式化之后的字符
//循环控制显示的内容及格式
for(int i = 0; i < Math.Ceiling(str.Length/(float)wordsInRow); i ++)
{
//控制每行显示的内容
if (str.Length - numId * wordsInRow >= wordsInRow)
returnStr += "行:<font color=red>" + (numId+1)+"</font>:"+str.Substring(numId * wordsInRow,wordsInRow) + "<BR>";
else
returnStr += "行:<font color=red>" + (numId+1) + "</font>:" + str.Substring(numId * wordsInRow, str.Length - numId * wordsInRow) + "<BR>";
numId++;
}
return returnStr;
}
//格式化评论内容(截取就用这个)
protected string Famart(string str)
{
if (str.Length > 6)
{
return str.Substring(0, 5) + "...";
}
else
{
return str;
}
}
3.最后在前台就以“<%# Famart(Eval("CommentText").ToString())%> ” 去调用 刚才这个方法(传入参数)
<asp:DataList ID="DlCommentMess" runat="server" Width="128%" DataKeyField="CommentID" RepeatColumns="2">
<ItemTemplate>
<table align="center" width="75%">
<tr>
<td align="left">
<%--调用方法--%>
<%# Famart(Eval("CommentText").ToString())%>
</td>
</tr>
<tr>
<td align="left">
网名:<%#Eval("CommentFromName")%><br />
E-mail:<%#Eval("CommentFromWebURL")%><br />
评论时间:<%#Eval("CommentDateSubmitted")%>
<hr color="#CCCCCC" noshade="noshade" size="2">
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
相关文章推荐
- jsp页面中如何将时间戳字符串格式化为时间标签
- 当聊天室的内容超出页面范围时, 如何让页面刷新后 显示最下面的内容
- 如何将从数据库中读出的带有html标签的字符串,让标签起效,显示在前台页面
- Android : 如何在WebView显示的页面中查找内容
- SSH如何将从数据库中读出的带有html标签的字符串,让标签起效,显示在前台页面
- flask如何完成数据库内容在html页面上的显示以及相应数据的删除
- webbrowser如何将网页内容保存为字符串以及根据字符串显示成网页
- SugarCRM - 如何在Contact的详细页面修改显示内容
- Pega How To系列之一:如何在页面上动态显示/隐藏内容 ----CheneyWang
- (转)获取HTML页面内容后格式化显示的办法
- 【WPF学习笔记】之如何把数据库里的值读取出来然后显示在页面上:动画系列之(六)(评论处有学习资料及源码)
- 如何在JSP页面显示Oracle数据库内容
- 如何在JSP页面显示mysql数据库内容 (二)
- 如何在html页面显示<…>标签内容
- 如何去掉从数据库中读出的带有html标签的字符串,并是标签起效,显示在前台页面
- 如何在一个页面内点击一个按钮,然后在下方显示内容?
- 如何将从数据库中读出的带有html标签的字符串,让标签起效,显示在前台页面
- 如何在JSP页面显示mysql数据库内容 (二)
- 如何使用JS实现页面内容随机显示
- 如何将从数据库中读出的带有html标签的字符串,让标签起效,显示在前台页面