runtime Gridview - running number

Discussion in 'ASP .Net' started by Tony WONG, Apr 20, 2010.

  1. Tony WONG

    Tony WONG 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
     
    Tony WONG, Apr 20, 2010
    #1
    1. Advertising

  2. On Apr 20, 11:37 am, "Tony WONG" <> 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
     
    Alexey Smirnov, Apr 21, 2010
    #2
    1. Advertising

  3. Tony WONG

    Tony WONG Guest

    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" <>

    Try to change it to

    cb.Text = container.DataItemIndex + 1
     
    Tony WONG, Apr 21, 2010
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?a2w=?=

    Runtime Error on running aspx page on https://

    =?Utf-8?B?a2w=?=, Feb 4, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    3,191
    =?Utf-8?B?S2lt?=
    Feb 11, 2004
  2. Marina Anufreichik
    Replies:
    10
    Views:
    699
    Rajasekhar Patta
    Feb 17, 2005
  3. Priyanka AGARWAL
    Replies:
    4
    Views:
    5,252
    Priyanka AGARWAL
    Jul 23, 2004
  4. =?Utf-8?B?bWdvbnphbGVzMw==?=

    GridView Hierarchical View - Gridview in Gridview

    =?Utf-8?B?bWdvbnphbGVzMw==?=, May 9, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    17,986
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
    May 9, 2006
  5. Hal Vaughan
    Replies:
    11
    Views:
    1,131
    Gordon Beaton
    May 22, 2006
Loading...

Share This Page