Dean,
 
Maybe I am better off telling you my objective.  Perhaps I am approaching
this incorrectly.
 
I have a checkbox list of the fields in the table.  I want the user to be
able to generate a custom report sometimes displaying only specific fields.
I am unable to handle this in my query to pull just the specific fields for
reasons not relevant to this problem (that is how I would normally handle
it).  The Sproc returns ALL of the fields but I want the Grid to only
display the ones that were checked.
 
Thus I thought dynamically building the template would allow the BIND to
bind to just the templated columns.
 
Does that help?
 
Ronda

  _____  

From: Ronda [mailto:[EMAIL PROTECTED] 
Sent: Friday, August 27, 2004 12:23 PM
To: [EMAIL PROTECTED]
Subject: RE: [AspNetAnyQuestionIsOk] Dynamic Template Class


Dean,

Because I am looping through a collection I am building the template columns
one at a time.  I bind after this loop.  The only difference between the
example is that they bind in the class... which would put me binding and
rebinding in the loop.

Below is the Class
------------------------
Public 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
        Dim lc As New Literal()
        Select Case templateType
            Case ListItemType.Header
                lc.Text = "<B>" & columnName & "</B>"
                container.Controls.Add(lc)
            Case ListItemType.Item
                lc.Text = "Item " & columnName
                'I tried the following line but it renders too late
                'lc.Text = "<%# container.dataitem(""" & columnName &
""")%>"
                container.Controls.Add(lc)
            Case ListItemType.EditItem
                Dim tb As New TextBox()
                tb.Text = ""
                container.Controls.Add(tb)
            Case ListItemType.Footer
                lc.Text = "<I>Footer</I>"
                container.Controls.Add(lc)
        End Select
    End Sub

End Class

________________________________

From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Friday, August 27, 2004 12:17 PM
To: [EMAIL PROTECTED]
Subject: Re: [AspNetAnyQuestionIsOk] Dynamic Template Class


Binding doesn't happen automatically for template columns, you need to
handle 
your own binding.  Have you created the DataBinding event as suggested by
the 
article?  You can also manually handle the binding in the grid's
ItemDataBound

event, which is not as elegant but works.

Why don't you post the code for DataGridTemplate.

HTH,

Dean Fiala
Very Practical Software, Inc.

http://www.vpsw.com

> 
> I am having a problem passing Data to a Template Class - the code for the
> template class I am using is similar to the code listed here:
>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/
> vbtskcreatingwebservercontroltemplatesdynamically.asp
> 
> It is working fine but for some reason once it creates the template in the
> page I am not dynamically binding in other words the Grid is not populated
> with the data but with the text I passed.  I feel like it is the order
that
> I am approaching it.  I am binding after the template is created but am
> getting the text I send to the template back as the value.  If anyone can
> glance at this and offer a suggestion I would appreciate it. TIA  ~ Ronda
> 
> -------------------------------
> My code below
> --------------------------------
> Sub pullRecords(ByVal sender As System.Object, ByVal e As
System.EventArgs)
>        
>         Dim sql As System.String = "GetOrderDetails"
>         Dim returnValue As System.Int32
>         Dim storeCode As String = txtProductCode.Text
>         Dim begOrder As String = txtBegOrder.Text
>         Dim endOrder As String = txtEndOrder.Text
>  
>         Dim conDB As New SqlConnection(Me.conString)
>         conDB.Open()
> 
>         Dim cmdReturn As New SqlCommand(sql, conDB)
>         cmdReturn.CommandType = CommandType.StoredProcedure
>         'Removed passing the parameters to the sproc
>         Dim SqlDataAdapter1 As New SqlDataAdapter()
>         SqlDataAdapter1.SelectCommand = cmdReturn
>         Dim DsCategories1 As New DataSet()
> 
> 
> 
>         Dim ListItem As ListItem
>         For Each ListItem In chkShow.Items
>           'Ideally I am checking the CHECKED checkboxes 
>           'but right now I am just trying to get it to work at all
>             Dim tc1 As New TemplateColumn()
>             tc1.HeaderTemplate = New DataGridTemplate(ListItemType.Header,
> ListItem.Text)
>             tc1.ItemTemplate = New DataGridTemplate(ListItemType.Item,
> ListItem.Text)
>             tc1.FooterTemplate = New DataGridTemplate(ListItemType.Footer,
> ListItem.Text)
>             dgOrders.Columns.Add(tc1)
>         Next
> 
>         SqlDataAdapter1.Fill(DsCategories1, "orders")
>         dgOrders.DataSource = DsCategories1.Tables("orders")
>         dgOrders.DataBind()
> 
>         conDB.Close()
>         conDB.Dispose()
> 
>     End Sub


[Non-text portions of this message have been removed]



------------------------ Yahoo! Groups Sponsor --------------------~--> 
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/saFolB/TM
--------------------------------------------------------------------~-> 

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 

Reply via email to