From: Tony WONG on
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


From: Alexey Smirnov on
On Apr 20, 11:37 am, "Tony WONG" <x...(a)netvigator.com> wrote:
> 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
From: Tony WONG on
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" <alexey.smirnov(a)gmail.com>

Try to change it to

cb.Text = container.DataItemIndex + 1