runtime Gridview - running number

  • Thread starter Thread starter Tony WONG
  • Start date Start date
T

Tony WONG

in design mode, the following vb code is always used to have a running
number in gridview table.
<%# Container.DataItemIndex + 1 %>

Now i need to create gridview at RUNTIME

i try to make use of the following code but i do not know how to put in the
vb code in the Class part

it seems it is not a label. Grateful for any idea. thanks a lot.
*****************************
Public Class CreateRunningNo
Implements ITemplate

Public Sub InstantiateIn(ByVal container As System.Web.UI.Control)
Implements System.Web.UI.ITemplate.InstantiateIn
Dim cb As New Label
cb.Text = "<%# Container.DataItemIndex + 1 %>"
container.Controls.Add(cb)
End Sub
End Class
 
in design mode, the following vb code is always used to have a running
number in gridview table.
<%# Container.DataItemIndex + 1 %>

Now i need to create gridview at RUNTIME

i try to make use of the following code but i do not know how to put in the
vb code in the Class part

it seems it is not a label.  Grateful for any idea.  thanks a lot.
*****************************
    Public Class CreateRunningNo
        Implements ITemplate

        Public Sub InstantiateIn(ByVal container As System.Web.UI..Control)
Implements System.Web.UI.ITemplate.InstantiateIn
            Dim cb As New Label
            cb.Text = "<%# Container.DataItemIndex + 1 %>"
            container.Controls.Add(cb)
        End Sub
    End Class

The line

cb.Text = "<%# Container.DataItemIndex + 1 %>"

will not work because <%# %> could be used in the aspx only.

Try to change it to

cb.Text = container.DataItemIndex + 1
 
Thanks Alexey

i cannot call "DataItemIndex" after container


finally i solve by
Dim a = 1
Public Sub InstantiateIn(ByVal container As System.Web.UI.Control)
Implements System.Web.UI.ITemplate.InstantiateIn
Dim cb As New Label
cb.Text = a
a += 1
container.Controls.Add(cb)
End Sub

it seems your code look more smart. if you have any idea to make it in your
way. let me know.


"Alexey Smirnov" <[email protected]>

Try to change it to

cb.Text = container.DataItemIndex + 1
 
Back
Top