如题。
是不是把 HeaderStyle-Width FooterStyle-Width ItemStyle-Width 这三个同时设上? 必须设成同样宽度吗?
还是设置<ItemTemplate>里的Label的长度?
还是设置<EditItemTemplate>里的Label的长度?

解决方案 »

  1.   

    <div style="overflow:hidden;width:200px;text-overflow:ellipsis">打开抗敌素可打开撒开绿灯撒恺撒棵扩大上爱迪生啊撒大可</div>不建议用这种方法 不同浏览器支持不太好
    最好在datarowbound事件里处理一下字符串
      

  2.   

    我比较喜欢在代码里处理掉
     str="sadfasffasgdggsadgfasfgas";
     newstr=str.Length>20?str.SubString(0,20)+"...":str;
      

  3.   

    http://topic.csdn.net/u/20080801/09/53599284-366d-4212-80a1-eeef55ce26ef.html
    你看看这个贴子吧。
      

  4.   

     
    下面代码是设置<ItemTemplate>里的Label的长度并把多余的字截掉或显示“…” 
     protected void rpLogRecycleBin_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType != ListItemType.Header && e.Item.ItemType != ListItemType.Footer)
            {
                HiddenField HTitle = e.Item.FindControl("HFTitle") as HiddenField;
                Literal ltTitle = e.Item.FindControl("ltTitle") as Literal;
                if (HTitle.Value.Length > 30)
                {
                    ltTitle.Text = HTitle.Value.ToString().PadRight(30).Substring(0, 30) + "...";
                }
                else { ltTitle.Text = HTitle.Value.ToString(); }
            }
          
        }
      

  5.   

    我们在编辑GridView数据时。有时候数据过长会把设计好的table给撑开;下面是解决方法: 
    <asp:TemplateField SortExpression="sortname"> 
    <EditItemTemplate><asp:TextBox ID="TextBox1" runat="server" BorderWidth="1px"  BorderStyle="Solid" Text='<%# Bind("sortname") %>'></asp:TextBox></EditItemTemplate><ItemTemplate> 
    <asp:Label ID="Label1" runat="server"  Text='<%# Bind("sortname") %>' Width="100px"></asp:Label> </ItemTemplate></asp:TemplateField> 
    //给文本框赋颜色,长度 
        protected void grSort_RowDataBound(object sender, GridViewRowEventArgs e) 
        { 
            if ((e.Row.RowState & DataControlRowState.Edit) == DataControlRowState.Edit) 
            { 
    ((TextBox)e.Row.FindControl("TextBox1")).Width = 102; 
    ((TextBox)e.Row.FindControl("TextBox1")).BorderColor = System.Drawing.ColorTranslator.FromHtml("#73C547"); 
            } 
        } 
    不过在修改过程代码要改动一下。不能和以前一样 
    ((TextBox)(grSort.Rows[e.RowIndex].Cells[0].Controls[1])).Text.Trim() 以前我们写的是Controls[0]是因为那是直接绑定的。现在改成1是应为textbox1是第一个控件。因此从第一个开始。(也许这里我理解有误) 
     
      

  6.   

    Eval("Name").ToString().Length>14?Eval("Name").ToString().Substring(0,15)+"...":Eval("Name")
      

  7.   

    str="sadfasffasgdggsadgfasfgas";
    newstr=str.Length>20?str.SubString(0,20)+"...":str; 
    这个应该是比较好的。而且比较容易理解