<asp:Repeater ID="RepeaterList" runat="server">
<ItemTemplate>
<table width="410" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="380" id="q_title">
<strong>◆ <a href="QuestionDetail.aspx?questionid=<%#Eval("question_id")%>&gid=<%#Eval("category_group_id")%>">
<%#Eval("question_title") %></strong> </a>
</td>
</tr>
<tr>
<td id="q_content">
<br /><strong>
<asp:Label ID="lblQuestion_content" runat="server" Text="答案:"></asp:Label></strong><asp:Label ID="lblContent" truncateToFit="true" maxWidth="25" runat="server" ForeColor="Gray" Text='<%#Eval("answer_content") %>'></asp:Label>
</td>
</tr>
<tr>
<td width="375">
<hr />
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>我的repeater绑定table了,一个问题和一个答案显示如下:
◆ 为什么问题这么多
答案:没有最好,但求更好!
————————————
◆ 为什么
答案:为什么的答案
————————————
◆ 为什么1
答案:为什么1的答案
....加入有一个问题的答案 结果N长...他也会全部显示出来这样影响美观加入答案字数到了20个就显示20个,后面就显示...效果如下:
ssfdadfsdfs...
{
if (str == null || str.Trim() == "")
{
return "";
}
if (str.Length < len)
{
return str;
}
StringBuilder sb = new StringBuilder();//新字符串
sb.Append(str.Substring(0, len));
if (word.Trim() != "")
{
sb.Append(word);
}
return sb.ToString();
}
2.word-break:keep-all;/* 不换行 */
3.white-space:nowrap;/* 不换行 */
4.overflow:hidden;/* 内容超出宽度时隐藏超出部分的内容 */
5.text-overflow:ellipsis;/* 当对象内文本溢出时显示省略标记(...) ;需与overflow:hidden;一起使用。*/ 其实没必要一定要20个字就省略 你只要把一个DIV的宽度写死 然后加上 上面的样式。就OK。
text-overflow:ellipsis;word-break:keep-all;word-warp:warp;white-space:nowrap;
{
if (str.Length > 20)
{
return str.Substring(0, 20) + "....";
}
else
{
return str;
}
}<%# CutStr(Eval("question_title").ToString()) %>
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[2].ToolTip = e.Row.Cells[2].Text;
if (e.Row.Cells[2].Text.Length > 50)
{
e.Row.Cells[2].Text = e.Row.Cells[2].Text.Substring(0, 49) + "... ";
}
}
}以前写gridview时用的,稍微改下应该就行了
((Eval("dis_content")).ToString())
%>
<td id="q_content" style="text-overflow:ellipsis;word-break:keep-all;word-warp:warp;white-space:nowrap;">你的内容</td>