TemplateColumn databinding in DataGrid

TemplateColumn databinding in DataGrid

Post by Lei Guangf » Sat, 15 Jun 2002 11:03:06


I use DataGrid to show data in webpage, also I add a
template column with a Checkbox control. What I want to do
is binding the Checkbox to the same datasource of the

How can I carry it out? can you give me some help?

Thanks in advance.

Lei Guangfu


1. restoring dynamically added (databound) templatecolumns from viewstate

I've made my own templatecolumn programmatically (as shown in
in which i create a PlaceHolder to which i add LinkButtons on
databinding(sounds complicated i know...) Here's the implemented

    Public Sub InstantiateIn(ByVal container As Control) Implements
        Dim ph As PlaceHolder = New PlaceHolder()
        Select Case templateType
            Case ListItemType.Header
            Case ListItemType.Item
                AddHandler ph.DataBinding, AddressOf
        End Select
    End Sub

    Private Sub TemplateControl_DataBinding(ByVal sender As Object,
ByVal e As System.EventArgs)
        Dim ph As PlaceHolder = CType(sender, PlaceHolder)
        Dim container As DataGridItem = CType(ph.NamingContainer,
        Dim value As Object = DataBinder.Eval(container.DataItem,
        If Not IsDBNull(kew_ids) Then
            ph.Controls.Add(...somecontrol which uses the databound
        End If
    End Sub

Now, the problem is: when i re-add the columns on postback (in
LoadViewState, i know that much...), the column-headers show up
perfectly, but the cells (in which the LinkButtons are supposed to be)
are all empty (yes, i've given all of them an id). I can explain this
to some degree, as the Item only has a databinding handler. When i do
a DataBind() they do show up.
So this makes my question: is it possible to restore the items (cells)
ViewState without having to databind everytime? I'm guessing i would
have to save ViewState in the databind-handler and add an extra
handler to programmatically restore it or something?

thanks in advance,


2. Windows NT 4.0 Server, FW-1, 3NIC's and a strange problem

3. .NET Add-ins in Excel do not show up in Add-ins

4. SCSI & A1200 quest.

5. Datagrid TemplateColumns: EditItem FindControl not finding submitted textbox values?

6. : MikTeX

7. Can't get SelectedItemStyle to work with DataGrid's TemplateColumn setups.

8. Bandwidth speed test results

9. Datagrid TemplateColumn and Select list

10. DataGrid - TemplateColumn

11. DataGrid templateColumn

12. BUG? TemplateColumn in DataGrid Visible=False

13. have 5 master TemplateColumns followed by detail datagrid?