Asp Hyperlink and Datalist Question

L

Leon

What Am I Doing Wrong? Code Will Not Run, I Can't See The Error! Thanks.

<asp:datalist id="DataList1" runat="server"
RepeatColumns="4">
<ItemTemplate>
<asp:HyperLink
id=HyperLink1
ImageUrl= '<%# String.Format("Toyota/Images/Showroom/" &
Container.DataItem("PathToDisplyPic"))%>'
NavigateUrl='<%#
String.Format("Toyota/Display.aspx/ConsultantId=1&DisplayId={0})",
Container.DataItem("ID"))%>' runat="server" /><BR>
<asp:Label id="Label1" runat="server">Label</asp:Label>
</ItemTemplate>
</asp:datalist>
 
K

Ken Cox [Microsoft MVP]

Hi Leon,

You had some syntax errors. When I fix those, it runs. Not sure what it is
supposed to look like though. See the code below.

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]
Toronto

<asp:datalist id="DataList1" runat="server" RepeatColumns="4">
<ItemTemplate>
<asp:HyperLink id=HyperLink1
ImageUrl= '<%# String.Format("Toyota/Images/Showroom/" &
Container.DataItem("PathToDisplyPic"))%>'
NavigateUrl='<%#
String.Format("Toyota/Display.aspx?ConsultantId=1&DisplayId={0}",
Container.DataItem("ID"))%>' runat="server" /><BR>
<asp:Label id="Label1" runat="server">Label</asp:Label>
</ItemTemplate>
</asp:datalist>

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
DataList1.DataSource = CreateDataSource()
DataList1.DataBind()
End If
End Sub
Function CreateDataSource() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn _
("ID", GetType(Int32)))
dt.Columns.Add(New DataColumn _
("PathToDisplyPic", GetType(String)))
Dim i As Integer
For i = 0 To 4
dr = dt.NewRow()
dr(0) = i
dr(1) = "path" + i.ToString()
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSource
 
L

Leon

Thanks everything works fine now, but...
How do I separate each pair of Hyperlink & Label with a space horizontal?

Ken Cox said:
Hi Leon,

You had some syntax errors. When I fix those, it runs. Not sure what it is
supposed to look like though. See the code below.

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]
Toronto

<asp:datalist id="DataList1" runat="server" RepeatColumns="4">
<ItemTemplate>
<asp:HyperLink id=HyperLink1
ImageUrl= '<%# String.Format("Toyota/Images/Showroom/" &
Container.DataItem("PathToDisplyPic"))%>'
NavigateUrl='<%#
String.Format("Toyota/Display.aspx?ConsultantId=1&DisplayId={0}",
Container.DataItem("ID"))%>' runat="server" /><BR>
<asp:Label id="Label1" runat="server">Label</asp:Label>
</ItemTemplate>
</asp:datalist>

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
DataList1.DataSource = CreateDataSource()
DataList1.DataBind()
End If
End Sub
Function CreateDataSource() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn _
("ID", GetType(Int32)))
dt.Columns.Add(New DataColumn _
("PathToDisplyPic", GetType(String)))
Dim i As Integer
For i = 0 To 4
dr = dt.NewRow()
dr(0) = i
dr(1) = "path" + i.ToString()
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSource

Leon said:
What Am I Doing Wrong? Code Will Not Run, I Can't See The Error! Thanks.

<asp:datalist id="DataList1" runat="server"
RepeatColumns="4">
<ItemTemplate>
<asp:HyperLink
id=HyperLink1
ImageUrl= '<%# String.Format("Toyota/Images/Showroom/" &
Container.DataItem("PathToDisplyPic"))%>'
NavigateUrl='<%#
String.Format("Toyota/Display.aspx/ConsultantId=1&DisplayId={0})",
Container.DataItem("ID"))%>' runat="server" /><BR>
<asp:Label id="Label1" runat="server">Label</asp:Label>
</ItemTemplate>
</asp:datalist>
 
K

Ken Cox [Microsoft MVP]

Leon said:
Thanks everything works fine now, but...
How do I separate each pair of Hyperlink & Label with a space horizontal?

Sorry, I'm not sure what you mean. Could you show me what it should look
like in regular HTML? You currently have four columns. There's a label below
each link. Perhaps you can clarify?

Thanks,

Ken
 
L

Leon

This is what it should look like..

Hyperlink -Space- Hyperlink -Space- Hyperlink -Space- Hyperlink
Label Label Label
Label
|Space
Hyperlink Hyperlink Hyperlink
Hyperlink
Label -Space- Label -Space- Label -Space-
Label
ECT....
 
K

Ken Cox [Microsoft MVP]

Hi Leon,

You could throw in some non-breaking spaces to do that.

<asp:datalist id="DataList1" runat="server" RepeatColumns="4">
<ItemTemplate>
<asp:HyperLink id=HyperLink1
ImageUrl= '<%# String.Format("Toyota/Images/Showroom/" &
Container.DataItem("PathToDisplyPic"))%>'
NavigateUrl='<%#
String.Format("Toyota/Display.aspx?ConsultantId=1&DisplayId={0}",
Container.DataItem("ID"))%>' runat="server"
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>
<asp:Label id="Label1" runat="server">Label</asp:Label><br />
</ItemTemplate>
</asp:datalist>
 
L

Leon

Thanks, but would it be best for me to put the
itemtemplate info in a html table <tr>.

Thanks again Ken!
 
Y

Yunus Emre ALPÖZEN [MCAD.NET]

1. Are u sure you attached a data source your datalist ?
2. HyperLink NavigateUrl "Toyota/Display.aspx/ConsultantId=1&DisplayId={0}"
is it correct? "Toyota/Display.aspx?ConsultantId=1&DisplayId={0}"
3. What is wrong ? What about output ? Can u see anything?
 
L

Leon

I'm sure! I see the data perfect, but now I'm trying to format the
data exactly the way I want it.
 
Y

Yunus Emre ALPÖZEN [MCAD.NET]

Ok. I couldnot understand your question... Is it possible to describe your
problem briefly?

--

Thanks,
Yunus Emre ALPÖZEN
BSc, MCAD.NET
 

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,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top