GridView实现用“...”代替超长字符串:

解决方法:数据绑定后过滤每一行即可

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;

    }

你可能感兴趣的:(GridView)