Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic datagrid column with an inherited ITemplate column

Status
Not open for further replies.

tyris

Programmer
Nov 2, 2000
311
FR
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:

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)
I wonder where my error is...

=============================================
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-)
 
forget my question i don't need an answer any more :) Best regards,
Elise, XML girl X-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top