<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...

解决方案 »

  1.   

     protected string CutString(string str, int len, string word)
            {
                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.   

    StringBuilder 是社么意思啊?是不是需要引用什么? Using之类的...?
      

  3.   

    1.table-layout:fixed;/* 只有定义了表格的布局算法为fixed,下面td的定义才能起作用。 */   
    2.word-break:keep-all;/* 不换行 */   
    3.white-space:nowrap;/* 不换行 */   
    4.overflow:hidden;/* 内容超出宽度时隐藏超出部分的内容 */   
    5.text-overflow:ellipsis;/* 当对象内文本溢出时显示省略标记(...) ;需与overflow:hidden;一起使用。*/  其实没必要一定要20个字就省略 你只要把一个DIV的宽度写死  然后加上 上面的样式。就OK。
      

  4.   


    text-overflow:ellipsis;word-break:keep-all;word-warp:warp;white-space:nowrap;
      

  5.   

    public string CutStr(string str)
        {
            if (str.Length > 20)
            {
                return str.Substring(0, 20) + "....";
            }
            else
            {
                return str;
            }
        }<%# CutStr(Eval("question_title").ToString()) %>
      

  6.   


            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时用的,稍微改下应该就行了
      

  7.   

        <%#Eval("dis_content").ToString().Length>25?((Eval("dis_content")).ToString().Substring(0,25))+"…":
                                                         ((Eval("dis_content")).ToString())   
                                                          
                                                                                    %>
      

  8.   

    其实有这一段就可以了 上面是复制的- -!!overflow:hidden;text-overflow:ellipsis 
      

  9.   

    td里面加个div标签,div里面加style="width:100px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;"具体的宽度自己调
      

  10.   


    <td id="q_content" style="text-overflow:ellipsis;word-break:keep-all;word-warp:warp;white-space:nowrap;">你的内容</td>