在手动减少datagridview某列的列宽是,如果文字的长度大于列宽,文字会自动换行。但我想设置为把文字截断,该怎么设置呢!

解决方案 »

  1.   

    解决方法:数据绑定后过滤每一行即可
    for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
            {
                DataRowView mydrv;
                string gIntro;
                if (GridView1.PageIndex == 0)
                {
                    mydrv = myds.Tables["飞狐工作室"].DefaultView[i];//表名
                    gIntro = Convert.ToString(mydrv["家庭住址"]);//所要处理的字段
                    GridView1.Rows[i].Cells[3].Text = SubStr(gIntro, 2);
                }
                else
                {
                    mydrv = myds.Tables["飞狐工作室"].DefaultView[i + (5 * GridView1.PageIndex)];
                    gIntro = Convert.ToString(mydrv["家庭住址"]);
                    GridView1.Rows[i].Cells[3].Text = SubStr(gIntro, 2);
                }
            } 调用的方法:    public string SubStr(string sString, int nLeng)
        {
            if (sString.Length <= nLeng)
            {
                return sString;
            }
            string sNewStr = sString.Substring(0, nLeng);
            sNewStr = sNewStr + "...";
            return sNewStr;
        }
      

  2.   

    protected void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
     string temp = e.Item.Cells[6].Text;
                    if (!temp.Equals("") && !temp.Equals("&nbsp;"))
                    {
                        if (temp.Length > 15)
                        {
                            e.Item.Cells[6].Text = temp.Substring(0, 15) + "...";
                        }
                        e.Item.Cells[6].Attributes.Add("title", temp);
                    }
    }
      

  3.   

     protected string len(string myle, int le)//截取超过一定字符串长度
        {
            string mylen = myle.ToString();
            string ert = mylen;
            if (mylen.Length > le)
            {
                ert = myle.Substring(0, le) + "...";
            }
            return ert;
        }