<%# DataBinder.Eval(Container.DataItem,"字段").ToString().Substring(0,15)+"……"%>

解决方案 »

  1.   

    你可以自己限定显示多少个字符,如果多余限定字符就已……显示:
    private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    string strID = "";
       if (e.Item.ItemType == ListItemType.Item ||e.Item.ItemType ==ListItemType.AlternatingItem)
    {
    if (e.Item.Cells[1].Text.Length >26)
    {
    e.Item.Cells[1].Attributes.Add("内容",e.Item.Cells[1].Text);
    e.Item.Cells[1].Text = e.Item.Cells[1].Text.Substring(0,26)+"…………";
    }
       

    }
    }
    e.Item.Cells[1]改成你要限制的那一列
      

  2.   

    在itembound事件中加入下列代码:
    if(e.item.ItemType != ItemTypeList.Header && e.item.ItemType != ItemTypeList.booter)
    {
    for(int i = 0 ; i < e.item.Cells.Count;i++)
    {
    string strText = e.item.Cells[i].Text;
    if (strText.Length >20)
    {
     e.item.Cells[i].Text = strText.SubString(0,17)+'...';
    }
    }
    }
      

  3.   

    这样写是否简单?
    <%#DataBinder.Eval(Container.DataItem, "yourKeyField").ToString().Length > 20?DataBinder.Eval(Container.DataItem, "yourKeyField").ToString().Substring(0,20)+"...":DataBinder.Eval(Container.DataItem, "yourKeyField")%>
      

  4.   

    以上的答案都不能解决DataGrid的宽度按百分比自动适应浏览器的宽度这种情况,因为列宽不固定,要在用户用鼠标调整DataGrid宽度的时候算出每列能容纳多少字符还比较麻烦