0 Replies - 823 Views - Last Post: 12 April 2013 - 06:38 AM Rate Topic: -----

#1 JClephane-Cameron   User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 14
  • Joined: 19-December 12

ASP.NET ListView Dynamic Template Creation

Posted 12 April 2013 - 06:38 AM

Hi All,

I'm pulling my hair out at the moment trying to work this out and I'm almost there. I am trying to dynamically create the ItemTemplate for a ListView for any given DataSource however I'm falling over on one point, binding the data to the dynamically created controls. I have created the controls themselves, added a handler for DataBinding but I can't work out what goes in the first parameter of DataBinder.Eval()

Please see my sample code below:

Private Class CustomItemTemplate

Implements ITemplate

Public Sub InstantiateIn(ByVal Container As System.Web.UI.Control) Implements System.Web.UI.ITemplate.InstantiateIn
Dim HT As New HtmlTable
Dim HTR As New HtmlTableRow

Dim TC As New HtmlTableCell
Dim L As New Label
L.ID = "Column1Label"
AddHandler L.DataBinding, AddressOf Column1Label_DataBinding


End Sub

Private Sub Column1Label_DataBinding(ByVal Sender As Object, ByVal e As EventArgs)
Dim L As Label = Sender
Dim S As String = DataBinder.Eval(<WHAT-GOES-HERE?>, "FirstColumn")
L.Text = S
End Sub

End Class]

If anyone knows the answer please help!

>> Jim <<

Is This A Good Question/Topic? 0
  • +

Page 1 of 1