DataGrid绑定列如何截取字符串(不改数据源)?

在ItemDataBound事件中写

if (e.Item.ItemType != ListItemType.Header && e.Item.ItemType != ListItemType.Footer && e.Item.ItemType != ListItemType.Pager)
        {
            string str = e.Item.Cells[5].Text;  //取出原来的值
            if (str.Length > 20)                //判断长度
            {
                str = str.Substring(0, 20);       //截取前十个字符
                e.Item.Cells[5].Text = str;       //把新值绑定到原来的位置
            }
        } 

posted @ 2008-06-27 17:09  俊哥哥  阅读(601)  评论(1编辑  收藏  举报