TemplateColumn databinding in DataGrid

TemplateColumn databinding in DataGrid

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



Hi,

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
Datagrid.

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

Hi,
I've made my own templatecolumn programmatically (as shown in
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_v...)
in which i create a PlaceHolder to which i add LinkButtons on
databinding(sounds complicated i know...) Here's the implemented
InstantiateIn:

    Public Sub InstantiateIn(ByVal container As Control) Implements
ITemplate.InstantiateIn
        Dim ph As PlaceHolder = New PlaceHolder()
        Select Case templateType
            Case ListItemType.Header
                ph.Controls.Add(...somecontrol...)
            Case ListItemType.Item
                AddHandler ph.DataBinding, AddressOf
TemplateControl_DataBinding
        End Select
        container.Controls.Add(ph)
    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,
DataGridItem)
        Dim value As Object = DataBinder.Eval(container.DataItem,
value)
        If Not IsDBNull(kew_ids) Then
            ph.Controls.Add(...somecontrol which uses the databound
value...)
        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)
from
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,

Mark.

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?