hi,
i'm making a code that generates TemplateColumns into a datagrid depending on a dataset, each column name is dynamic and not hard coded thanks to this.
I read many documentation on the net (mainly here : )
It's almost done (table is filled correctly, columns are generated) except one thing : clicking on Edit command does not display a textbox.
I created a "Edit" column and assigned the command "Edit" to the label (as i always do). So the problems is here is guess:
I wonder where my error is...
=============================================
here is the code sample :
=========================================
Do you have any clue to help me ?
Best regards,
Elise, XML girl X-)
i'm making a code that generates TemplateColumns into a datagrid depending on a dataset, each column name is dynamic and not hard coded thanks to this.
I read many documentation on the net (mainly here : )
It's almost done (table is filled correctly, columns are generated) except one thing : clicking on Edit command does not display a textbox.
I created a "Edit" column and assigned the command "Edit" to the label (as i always do). So the problems is here is guess:
Code:
Dim tc1 As TemplateColumn = New TemplateColumn()
tc1.ItemTemplate = New CTemplateColumn("test")
tc1.EditItemTemplate = New ValidateEditItem("test") 'HERE
tc1.HeaderText="my header"
DataGrid1.Columns.Add(tc1)
=============================================
here is the code sample :
Code:
Public Class ValidateEditItem
Implements ITemplate
Private colname As String
Public Sub New(ByVal cname As String)
colname = cname
End Sub
Public Sub InstantiateIn(ByVal container As Control) Implements ITemplate.InstantiateIn
Dim tb As TextBox = New TextBox()
AddHandler tb.DataBinding, AddressOf BindData
container.Controls.Add(tb)
tb.ID = colname
Dim rfv As RequiredFieldValidator = New RequiredFieldValidator()
rfv.Text = "Please Answer"
rfv.ControlToValidate = tb.ID
rfv.Display = ValidatorDisplay.Dynamic
rfv.ID = "validate" + tb.ID
container.Controls.Add(rfv)
End Sub
Public Sub BindData(ByVal sender As Object, ByVal e As EventArgs)
Dim tb As TextBox = CType(sender, TextBox)
Dim container As DataGridItem = CType(tb.NamingContainer, DataGridItem)
Dim drv As DataRowView = CType(container.DataItem, DataRowView)
tb.Text = CType(drv(colname), String)
End Sub
End Class
Do you have any clue to help me ?
Best regards,
Elise, XML girl X-)