Dynamic Web Controls

Discussion in 'ASP .Net Web Controls' started by Jay Esguerra, Sep 4, 2003.

  1. Jay Esguerra

    Jay Esguerra Guest

    Is it possible to do this:

    <%
    Dim i as integer

    For i = 65 to 90

    %>

    <asp:Linkbutton Text=chr(i) runat=server />

    <%
    Next
    %>

    *** I am trying to create a link button dynamically. Or
    is there another way...Keep in mind I am a newbie to .net
    and am accustomed to ASP.
    Jay Esguerra, Sep 4, 2003
    #1
    1. Advertising

  2. Jay Esguerra

    Ezra Epstein Guest

    The recommended approach is to use an ASP:Repeater control and then put the
    asp:LinkButton(s) (or whatever else) inside.

    For example:

    <snip>
    <asp:repeater id="ItemRepeater" Runat="server" DataSource="<%#
    CategoryContents %>">
    <ItemTemplate>
    <p class="CategoryItem">
    <asp:LinkButton ID="lnkShowUser" Runat="server" CausesValidation="false"
    CommandArgument='<%# DataBinder.Eval(Container.DataItem,
    "ReferencedItem.PkGuid") %>'>
    <%# DataBinder.Eval(Container.DataItem, "ReferencedItem.FullName") %>
    </asp:LinkButton>
    <br>
    <%# DataBinder.Eval(Container.DataItem, "ReferencedItem.PhoneNumber") %>
    </p>
    </ItemTemplate>
    <%-- SeparatorTemplate>
    <br>
    </SeparatorTemplate --%>
    </asp:repeater>
    </snip>

    The code-behind has a public CategoryContents property that returns an
    ICollection (something that can be enumerated). Then I use DataBinder.Eval
    to set a commandArgument (so that I can distinguish which ListButton was
    clicked). Finally you implement the call-back method for the repeater (not
    for the link button) and then distinguish the items based on the
    commandArgument.

    Hope that helps,

    Ezra E.

    "Jay Esguerra" <> wrote in message
    news:214b01c3731e$bb9eb760$...
    > Is it possible to do this:
    >
    > <%
    > Dim i as integer
    >
    > For i = 65 to 90
    >
    > %>
    >
    > <asp:Linkbutton Text=chr(i) runat=server />
    >
    > <%
    > Next
    > %>
    >
    > *** I am trying to create a link button dynamically. Or
    > is there another way...Keep in mind I am a newbie to .net
    > and am accustomed to ASP.
    Ezra Epstein, Sep 13, 2003
    #2
    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. Ronald
    Replies:
    2
    Views:
    823
    Robbe Morris [C# MVP]
    Jan 17, 2006
  2. Nathan Sokalski
    Replies:
    5
    Views:
    992
    Gaurav Vaish \(www.Edujini-Labs.com\)
    Jan 10, 2007
  3. Nathan Sokalski
    Replies:
    4
    Views:
    269
    Nathan Sokalski
    Dec 21, 2006
  4. Denny Smolinski via .NET 247

    Dynamic Controls, Placeholder, Retrieve Information from Dynamic Controls

    Denny Smolinski via .NET 247, May 4, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    454
    Eidolon
    May 4, 2004
  5. Nathan Sokalski
    Replies:
    4
    Views:
    307
    Nathan Sokalski
    Dec 21, 2006
Loading...

Share This Page