Dynamic Web Controls

J

Jay Esguerra

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.
 
E

Ezra Epstein

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.
 

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

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top