第一步,在aspx页你的GridView控件中加入onrowdatabound="ListView_RowDataBound" 或在属性栏进行设置
第二不,在aspx对应的cs页添加下代码
protected void ListView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)//判断数据类型
{
if(e.Row.Cells[1].Text.Length>6)//假设第1列(从0开始)是需要的数据,控制长度为6
{
e.Row.Cells[1].Text = e.Row.Cells[1].Text.Substring(0, 6) ;
}
}
}
第二不,在aspx对应的cs页添加下代码
protected void ListView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)//判断数据类型
{
if(e.Row.Cells[1].Text.Length>6)//假设第1列(从0开始)是需要的数据,控制长度为6
{
e.Row.Cells[1].Text = e.Row.Cells[1].Text.Substring(0, 6) ;
}
}
}