Adding HTMLAnchor

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello all,

I would like to add links dynamically as well as capture their ServerClick event deriving them from a table. How can I do that?

Here is what it would look like if I were to hard code it:

<tr><td bgcolor="#ffffff" height="17"><img height="7" src="../ReportsImages/navlink.gif" width="5"><a class="Normal" id="BankDetail" href="MainMenu.aspx" runat="server">Bank Detail</a></td></tr><tr><td bgcolor="#ffffff"><img height="7" src="../ReportsImages/navlink.gif" width="5"><a class="Normal" id="DailyBank" href="MainMenu.aspx" runat="server">Bank Summary</a></td></tr>

But what if I had a 100 of these... How would I add them using a table or a XML file?

I'd appreciate any input to help me resolve this.

Yamazed
 
How about using a DataList control with a Linkbutton in it? It creates a
table with hyperlinks inside that you can trap. Here's some sample code. Let
us know if it helps?

Ken
Microsoft MVP [ASP.NET]
Toronto


Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
DataList1.DataSource = CreateDataSource()
DataList1.DataBind()
End Sub

Sub DoClick _
(ByVal sender As Object, _
ByVal e As CommandEventArgs)
Label1.Text = "You chose: " & e.CommandArgument
Response.Redirect(e.CommandArgument)
End Sub

Function CreateDataSource() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn _
("IntegerValue", GetType(Int32)))
dt.Columns.Add(New DataColumn _
("StringValue", GetType(String)))
dt.Columns.Add(New DataColumn _
("CurrencyValue", GetType(Double)))
dt.Columns.Add(New DataColumn _
("Boolean", GetType(Boolean)))
Dim i As Integer
For i = 0 To 8
dr = dt.NewRow()
dr(0) = i
dr(1) = "myurl" + i.ToString() & ".aspx"
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSource

<form id="Form1" method="post" runat="server">
<P>
<asp:DataList id="DataList1" runat="server">
<ItemTemplate>
<asp:LinkButton id="LinkButton2" CommandName="Order"
OnCommand="DoClick" CommandArgument='<%# DataBinder.Eval(Container,
"DataItem.StringValue")%>' runat="server">
<%# DataBinder.Eval(Container, "DataItem.CurrencyValue")%>
</asp:LinkButton>
</ItemTemplate>
</asp:DataList></P>
<P>
<asp:Label id="Label1" runat="server"></asp:Label></P>
</form>
 
Hi Ken

No actually what I am looking for is to create a delegate of HTMLAnchor then invoking it... I did it in the past but I just can't seem to remember how I did it... I will figure it out with a little more time. I need simply to refresh my mind

Thank you though for your input

Yam

----- Ken Cox [Microsoft MVP] wrote: ----

How about using a DataList control with a Linkbutton in it? It creates a
table with hyperlinks inside that you can trap. Here's some sample code. Let
us know if it helps

Ke
Microsoft MVP [ASP.NET
Toront


Private Sub Page_Load
(ByVal sender As System.Object,
ByVal e As System.EventArgs)
Handles MyBase.Loa
DataList1.DataSource = CreateDataSource(
DataList1.DataBind(
End Su

Sub DoClick
(ByVal sender As Object,
ByVal e As CommandEventArgs
Label1.Text = "You chose: " & e.CommandArgumen
Response.Redirect(e.CommandArgument
End Su

Function CreateDataSource() As DataTabl
Dim dt As New DataTabl
Dim dr As DataRo
dt.Columns.Add(New DataColumn
("IntegerValue", GetType(Int32))
dt.Columns.Add(New DataColumn
("StringValue", GetType(String))
dt.Columns.Add(New DataColumn
("CurrencyValue", GetType(Double))
dt.Columns.Add(New DataColumn
("Boolean", GetType(Boolean))
Dim i As Intege
For i = 0 To
dr = dt.NewRow(
dr(0) =
dr(1) = "myurl" + i.ToString() & ".aspx
dr(2) = 1.23 * (i + 1
dr(3) = (i = 4
dt.Rows.Add(dr
Next
Return d
End Function 'CreateDataSourc

<form id="Form1" method="post" runat="server"><P><asp:DataList id="DataList1" runat="server"><ItemTemplate><asp:LinkButton id="LinkButton2" CommandName="Order"
OnCommand="DoClick" CommandArgument='<%# DataBinder.Eval(Container,
"DataItem.StringValue")%>' runat="server"><%# DataBinder.Eval(Container, "DataItem.CurrencyValue")%></asp:LinkButton></ItemTemplate></asp:DataList></P><P><asp:Label id="Label1" runat="server"></asp:Label></P></form
 
Back
Top