gridview如何将超长字符串自动截断,然后用省略号代替吗?知道的话把详细的步骤说明一下,谢谢
答案:2 悬赏:10 手机版
解决时间 2021-12-21 04:29
- 提问者网友:寂寞梧桐
- 2021-12-20 23:56
gridview如何将超长字符串自动截断,然后用省略号代替吗?知道的话把详细的步骤说明一下,谢谢
最佳答案
- 五星知识达人网友:天凉才是好个秋
- 2021-12-21 01:02
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
e.Row.Cells[0].Text = e.Row.Cells[0].Text.Length >10 ? "大于10" : "小于10";
}
{
if (e.Row.RowType == DataControlRowType.DataRow)
e.Row.Cells[0].Text = e.Row.Cells[0].Text.Length >10 ? "大于10" : "小于10";
}
全部回答
- 1楼网友:慢性怪人
- 2021-12-21 01:29
解决方法:数据绑定后过滤每一行即可 for (int i = 0; i <= gridview1.rows.count - 1; i++) { datarowview mydrv; string gintro; if (gridview1.pageindex == 0) { mydrv = myds.tables["a"].defaultview[i];//表名 gintro = convert.tostring(mydrv["家庭住址"]);//所要处理的字段 gridview1.rows[i].cells[3].text = substr(gintro, 2); } else { mydrv = myds.tables["a"].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; }
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯