Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > URGENT: Can not get dynamically created template column content

Reply
Thread Tools

URGENT: Can not get dynamically created template column content

 
 
Ahmet Gunes
Guest
Posts: n/a
 
      11-07-2003
As a requirement of our application each time different type and count of columns may be displayed to the user in a datagrid.
For this, I created a template by implementing ITemplate interface and added columns to the grid dynamically.
There is no problem with the display. But when I post back my grid gives Item.Count =0 and Columns.Count = 0.
Where did those items and columns go?

Please help,

Thanks in advance,


I create the columns with the following code:

gct = New GridColumnTemplate(ListItemType.Item, dv(i).Item("COLUMN_NAME"))
col = New TemplateColumn
col.ItemTemplate = gct
col.HeaderText = dv(i).Item("COLUMN_DESCRIPTION")
col.Visible = True
grdTranslator.Columns.Add(col)

And here is my template class:

Friend Class GridColumnTemplate
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
Dim lbl As New Label
lbl.Text = ""
AddHandler lbl.DataBinding, AddressOf TemplateControl_DataBinding
container.Controls.Add(lbl)
Case ListItemType.EditItem
Dim tb As New TextBox
tb.Text = ""
tb.ID = "txt" & columnName
tb.EnableViewState = False
AddHandler tb.DataBinding, AddressOf TemplateControl_DataBinding
container.Controls.Add(tb)
Case ListItemType.Footer
lc.Text = "<I>Footer</I>"
container.Controls.Add(lc)
End Select
End Sub

Private Sub TemplateControl_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs)
Select Case templateType
Case ListItemType.Header
Case ListItemType.Item
'Dim lc As Literal
'lc = CType(sender, Literal)
'Dim container As DataGridItem
'container = CType(lc.NamingContainer, DataGridItem)
'lc.Text = DataBinder.Eval(container.DataItem, columnName)
Dim lc As Label
lc = CType(sender, Label)
Dim container As DataGridItem
container = CType(lc.NamingContainer, DataGridItem)
lc.Text &= DataBinder.Eval(container.DataItem, columnName)
Case ListItemType.EditItem
Dim tb As TextBox
tb = CType(sender, TextBox)
Dim container As DataGridItem
container = CType(tb.NamingContainer, DataGridItem)
tb.Text &= DataBinder.Eval(container.DataItem, columnName)
Case ListItemType.Footer
End Select
End Sub
End Class



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pump data by row and column to dynamic created column in gridview johnsonlim026 ASP .Net 0 02-27-2010 05:29 PM
Affecting a dynamically created drop down from another dynamically created drop down. msimmons ASP .Net 0 07-16-2009 03:17 PM
get content of text boxes dynamically created tarscher@gmail.com ASP .Net 5 09-03-2006 08:47 AM
Adding a Directive to a dynamically created Template Column on gri Angel ASP .Net Web Controls 1 12-28-2005 09:40 PM
Managing ViewState of a dynamically created Custom Composite Server Control -(where the original is also dynamically created) dickster ASP .Net Building Controls 0 12-08-2005 09:32 AM



Advertisments