runtime Gridview - running number

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
 
G

Guest

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
 
T

Tony WONG

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.


"Anon User" <>

Try to change it to

cb.Text = container.DataItemIndex + 1
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top