效果圖:
解決方法:數據綁定後過濾每一行即可
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;
}