如题。最好能有代码,目前研究vb.net,c#也行。

解决方案 »

  1.   

    c#中,gridview列宽可以在gridview中的列的属性中可以设定。 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            //读取相关信息7个字符显示,这里是对第二列数据处理
                string str =e.Row.Cells[1].Text;
                //显示详细信息
                e.Row.Cells[1].ToolTip = str;//这个可以在鼠标放在这列上,就会显示详细的这列的内容
                //
                if (str.Length >= 7)
                {
                    e.Row.Cells[1].Text = str.Substring(0,7)+"<strong>...</strong>";
                }
    }
    上面的代码对中文处理,可能有时会取半个字符,所以还要优化一下。
      

  2.   

    for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                for (int j = 0; j < GridView1.Rows[i].Cells.Count; j++)
                {
                    string s = GridView1.Rows[i].Cells[j].Text;
                    string t = s;
                    if (s.Length >= 10)
                    {
                        t = s.Substring(0, 8) + "..";
                    }
                    GridView1.Rows[i].Cells[j].Text = t;
                    GridView1.Rows[i].Cells[j].ToolTip = t;
                    GridView1.Rows[i].Cells[j].Attributes.Add("ondbclick", "this.innerText = this.title");            }
    }
      

  3.   

    最好的办法是从数据库取数据的时候就取固定长度.如:select id,left(content,10) from t_news;
    然后再通过DataSet绑定到控件上,这样又可以节省服务器资源.
      GridView1.Column[0].Style.Width="100px"
      

  4.   

     DataTable dt = new DataTable();
            dt.Columns.Add("abc", typeof(string));
            DataRow dr = dt.NewRow();
            dr[0] = "abccccccccccccccccccccccc";
            dt.Rows.Add(dr);
            GridView1.DataSource = dt;
            GridView1.DataBind();        for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                for (int j = 0; j < GridView1.Rows[i].Cells.Count; j++)
                {
                    string s = GridView1.Rows[i].Cells[j].Text;
                    string t = s;
                    if (s.Length >= 10)
                    {
                        s = s.Substring(0, 8) + "..";
                    }
                    GridView1.Rows[i].Cells[j].Text =s ;
                    GridView1.Rows[i].Cells[j].ToolTip = t;
                    GridView1.Rows[i].Cells[j].Attributes.Add("onDblClick", "this.innerText = this.title");            }
            }测试了一下,db要分大小写.