可以在CS文件中写DataGrid1.ItemDataBound事件,
给段VB的代码进行参考:
If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.Item Then
e.Item.Cells(0).Text = formatstring(mytable.Rows(e.Item.ItemIndex)("orgid"))
End If
同意sping_ok和allanli,用TemplateColumn,在datagrid的itemdatabound事件中对string进行截取
例如:
strTmp = e.Item.Cells(8).Text '取得第九列里的string
If Len(strTmp) > 14 Then '如果它的长度大于15,就截取再补"..."
strTmp = Left(strTmp, 14) & "..."
End If