写一个格式化字符串的函数 string cutStr(string str,int len),在绑定datagrid的时候用,具体算法很简单,你应该可以写把.
另外把全部的的字符串内容写道title中.这样就可以将鼠标指向这一行,会显示每条信息标题的完整内容

解决方案 »

  1.   

    需要处理的字段按以下方法处理
    前台
    需要将实现你所要功能的列设置为模板列,例如:
    <asp:TemplateColumn>
    <ItemTemplate>
    <asp:Label runat="server" Text='<%# ShorterText(DataBinder.Eval(Container, "DataItem.YourText")) %>' ToolTip='<%# DataBinder.Eval(Container, "DataItem.YourText") %>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateColumn>
    后台增加一个protected的函数ShorterText
    protected string ShorterText(object obj)
    {
    string returnValue=object.toString().Trim();
    if(returnValue.Length>15)
    return returnValue.SubString(0,12)+"...";
    else
    return returnValue;
    }
      

  2.   

    上面的方法可行,也有另外一种方法,在后台循环给datagrid的每一项加入属性.前台的datagrid照常绑定(即不用模板列的方式).
    foreach(DataGridItem item in this.DataGrid1.Items)
    {
    item.Cells[1].Attributes["onmouseover"]="showlable('"+item.Cells[1].Text+"')";
    item.Cells[1].Attributes["onmouseout"]="hidelable()";
    //item.Cells[1].Text="1111";
    }然后,在客户端写showlable函数来显示该值,显示的方法可以用div层的方式.要注意层的定位问题,一般要通过获取当前鼠标坐标的方法来定位.客户端代码部分参考:
    div1.style.position="absolute";
    div1.style.background="red";
    div1.style.left=event.clientX;   //获取鼠标x坐标
    div1.style.top=event.clientY-10;
    div1.style.visibility="visible";
    .........