DataGrid动态添加控件
我想给datagrid每个单元格添加一个文本框,但是我这样做他只有最后一个add有效,本来我是用循环,但是运行的效果只有最后一列添加了textbox,其它列都没添加。这个问题应该如何解决,
求大神指教。
Private Sub dgdData_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgdData.ItemDataBound
Dim textbox As New TextBox
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
With textbox
.ID = "text"
.CssClass = "edline"
.Width = "130"
.Text = "sss"
End With
'For i As Integer = 0 To dgdData.Columns.Count - 1
e.Item.Cells(1).Controls.Add(textbox)
e.Item.Cells(2).Controls.Add(textbox)
'Next
End If
End Sub