S
Steve Mauldin
I am trying to take dynamically generated datagrid that is bound to a data
source and make one of the fields on the grid into an editable textbox that
is bound to a field from the data source. Using a microsoft example from
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html
/vbtskcreatingtemplatesprogrammaticallyindatagridcontrol.asp) I have been
able to get a textbox on to the grid using the datagrid.itemtemplate but it
is not bound to the data source field. The datagrid.edititemtemplate doe
not display the textbox. The example just leaves you hanging with a
textbox not linked to anything and what use is that? I am including my code
below. If anyone can tell me how to do the binding or what I am missing I
would greatly appreciate it. Thanks in advance.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
datagrid1 = New DataGrid
datagrid1.DataSource = AutoOrderPerson
datagrid1.ShowHeader = False
datagrid1.ShowFooter = False
datagrid1.GridLines = GridLines.None
datagrid1.BackColor = Color.White
datagrid1.Width = Unit.Percentage(100)
datagrid1.AutoGenerateColumns = False
Dim DataGridText As New TemplateColumn
'This Display nothing but is the code in the microsoft example
DataGridText.EditItemTemplate = New DataGridTemplate(ListItemType.EditItem,
"Quantity")
'This Displays unbound textbox
'DataGridText.ItemTemplate = New DataGridTemplate(ListItemType.EditItem,
"Quantity")
datagrid1.Columns.Add(DataGridText)
End Sub
Private Class DataGridTemplate
Implements ITemplate
Dim templateType As ListItemType
Dim columnName As String
Sub New(ByVal type As ListItemType, ByVal ColName As String)
templateType = type
columnName = ColName
End Sub
Sub InstantiateIn(ByVal container As Control) _
Implements ITemplate.InstantiateIn
Select Case templateType
Case ListItemType.EditItem
Dim tb As New TextBox()
tb.Text = ""
container.Controls.Add(tb)
End Select
End Sub
End Class
source and make one of the fields on the grid into an editable textbox that
is bound to a field from the data source. Using a microsoft example from
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html
/vbtskcreatingtemplatesprogrammaticallyindatagridcontrol.asp) I have been
able to get a textbox on to the grid using the datagrid.itemtemplate but it
is not bound to the data source field. The datagrid.edititemtemplate doe
not display the textbox. The example just leaves you hanging with a
textbox not linked to anything and what use is that? I am including my code
below. If anyone can tell me how to do the binding or what I am missing I
would greatly appreciate it. Thanks in advance.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
datagrid1 = New DataGrid
datagrid1.DataSource = AutoOrderPerson
datagrid1.ShowHeader = False
datagrid1.ShowFooter = False
datagrid1.GridLines = GridLines.None
datagrid1.BackColor = Color.White
datagrid1.Width = Unit.Percentage(100)
datagrid1.AutoGenerateColumns = False
Dim DataGridText As New TemplateColumn
'This Display nothing but is the code in the microsoft example
DataGridText.EditItemTemplate = New DataGridTemplate(ListItemType.EditItem,
"Quantity")
'This Displays unbound textbox
'DataGridText.ItemTemplate = New DataGridTemplate(ListItemType.EditItem,
"Quantity")
datagrid1.Columns.Add(DataGridText)
End Sub
Private Class DataGridTemplate
Implements ITemplate
Dim templateType As ListItemType
Dim columnName As String
Sub New(ByVal type As ListItemType, ByVal ColName As String)
templateType = type
columnName = ColName
End Sub
Sub InstantiateIn(ByVal container As Control) _
Implements ITemplate.InstantiateIn
Select Case templateType
Case ListItemType.EditItem
Dim tb As New TextBox()
tb.Text = ""
container.Controls.Add(tb)
End Select
End Sub
End Class