现在我用gridview绑定到数据库,但是有一列很长,有没有办法实现当绑定的时候显示前面几个字,当鼠标放上去的时候显示全部内容,郁闷阿

解决方案 »

  1.   

    当然可以.
    在RowDataBound上写事件
    随手写点代码,也许有语法错误.
    int i;
    i=e.Argument....;
    string s;
    s=Gridview1.Rows[i].Cells[10].Text;
    if (s.length>10)
    Gridview1.Rows[i].Cells[10].Text=s.Substring(0,6)+"...";
    ...
    ...
      

  2.   

    select    substring(field,1,12)+'...' as field from table1
      

  3.   

    static   public   string   Left(string   str,int   L)   
      {   
      string   tmpStr;   
      tmpStr=str;   
      if(str.Length>L)   
      {   
        
      tmpStr=str.Substring(0,L)+"..........";   
      }   
      return   tmpStr;   
      }   
        
      引用:   
      <%#   Left(Convert.ToString(DataBinder.Eval(Container,   "DataItem.tongzlr")),90)   %>
      

  4.   

    <a title='<%#Eval("ziduan").ToString() %>'><%#Eval("ziduan").ToString().Length > 5 ? Eval("ziduan").ToString().Substring(0, 5) : Eval("ziduan").ToString()%></a>
      

  5.   

    都这么麻烦,下面代码考过去,搞定
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)//不遍历行头和行尾
            {
                e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='LightSkyBlue'");//鼠标移入显示的颜色
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#ced7f7'");//鼠标移出显示的颜色           //这里就是你要的效果
    e.Row.Cells[2].ToolTip = e.Row.Cells[2].Text;            if (e.Row.Cells[2].Text.Length > 40)            {                e.Row.Cells[2].Text = e.Row.Cells[2].Text.Substring(0, 40) + "...";            }            e.Row.Cells[1].ToolTip = e.Row.Cells[1].Text;            if (e.Row.Cells[1].Text.Length > 8)            {                e.Row.Cells[1].Text = e.Row.Cells[1].Text.Substring(0, 8) + "...";            }
            }
        }
      

  6.   

    你把我那个里面的Index 改一下就行了,还有你要显示的长度的改一下,就OK了给分吧