//换行
DataGrid1.Attributes.Add("style","word-break:keep-all;word-wrap:normal");
当内容为数字 ,则必须
void DataGrid1_DataBound(Object sender, DataGridItemEventArgs e)
{
if( e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
e.Item.Cells[1].Text = "<nobr>" + e.Item.Cells[1].Text + "</nobr>";
}
或者
private void DataGrid1_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType ==ListItemType.Header||e.Item .ItemType==ListItemType.Item ||e.Item .ItemType ==ListItemType.AlternatingItem)
{
for(int i=0;i<e.Item .Cells .Count ;i++)
{
e.Item .Cells [i].Attributes .Add ("nowrap","nowrap");
}
}
}
//自动换行
DataGrid1.Attributes.Add("style","word-break:break-all;word-wrap:break-word");