How to put a list of items with hyperlinks under a label ?

F

fiefie.niles

I am new to ASP.Net. I use VB.NET as the language and Visual Studio
..NET 2003.
On my WebForm I have a label called "Categories".
I would like to read all the categories from the database and placed
them under the label "Categories". I also would like each category to
be a hyperlink to go to another page.
How can I do that ?
Using the codes below the categories are not placed under the label
"Categories", and there is no hyperlink for each item.
Thank you very much.

Dim sSQL As String
Dim drSQL As SqlClient.SqlDataReader
Dim cmdSQL As New SqlClient.SqlCommand()

sSQL = "GetCategories"
With cmdSQL
.Connection = g_Connection
.CommandText = sSQL
drSQL = .ExecuteReader()
End With
If drSQL.HasRows Then
Do While drSQL.Read
Response.Write(drSQL.Item("Categories") & "<br>")
Loop
End If
 
F

fiefie.niles

I can use Response.write like in the following codes, but is there a
better way to do it ?
Thanks.

Dim sSQL As String
Dim drSQL As SqlClient.SqlDataReader
Dim cmdSQL As New SqlClient.SqlCommand
Dim iCnt As Integer
Dim lID As Long

sSQL = "GetCategories 0"
With cmdSQL
.Connection = g_Connection
.CommandText = sSQL
drSQL = .ExecuteReader()
End With
If drSQL.HasRows Then
iCnt = 0
Do While drSQL.Read
iCnt += 1
lID = drSQL.Item("CatID")
Response.Write("<a id=HyperLink" & lID & _
" href=CategoryDetails.aspx?ID=" & lID & _
" style='Z-INDEX: 102; LEFT: 11px; POSITION: absolute;
TOP: " & (iCnt * 30) & "px'" & _
">" & drSQL.Item("Categories") & "</a>")
Loop
End If
 
R

Rob MacFadyen

Feifie,

You could use a databind for this (new in asp.net 2.0, if you're in 1.x
land... maybe a repeater?):

<asp:GridView
ID="CategoryGrid" runat="server"
DataKeyNames="Category"
AutoGenerateColumns="False"
GridLines="None"
<Columns>
<asp:HyperLinkField
DataTextField="Categories"
HeaderText="Categories"
DataNavigateUrlFields="Categories"
DataNavigateUrlFormatString="MyPage.aspx?Category={0}" />
</Columns>
</asp:GridView>

in the code behind set the DataSource to your reader:

Dim sSQL As String
Dim drSQL As SqlClient.SqlDataReader
Dim cmdSQL As New SqlClient.SqlCommand()

sSQL = "GetCategories"
With cmdSQL
.Connection = g_Connection
.CommandText = sSQL

CategoryGrid.DataSource = .ExecuteReader()

End With


Hope that helps.

Rob MacFadyen
 
F

fiefie.niles

Thank you.
If I install .NET Framework 2.0, can I use that with Visual Studio .NET
2003, or do I need to use Visual Studio .NET 2005 ?
Thanks.
 
F

fiefie.niles

Thank you.
I am currently using .NET Framework 1.1 with Visual Studio .NET 2003.
Is there a way to it in .NET 1.1 ?

If I install .NET Framework 2.0, can I use that with Visual Studio .NET
2003, or do I need to use Visual Studio .NET 2005 ?
Thanks.
 
R

Rob MacFadyen

FeiFie,

I don't think so.

I dithered a long time with asp.net 1.0/1.1 and really only started diving
into things with 2.0. Let me tell you it was well worth the wait. It is much
much much better that 1.0/1.1. The advanced databinding with the new
gridview alone are worth the price. So... I'd recommend upgrading :)

Or... look into using databinding with a DataGrid or Repeater. You should be
able to do something similar with the 1.0 controls.

Rob
 
P

Przemek Ptasznik

(e-mail address removed) napisał(a):
I can use Response.write like in the following codes, but is there a
better way to do it ?
Try to think of what you want to do: put _list_ of categories to
webpage,right?
So use markup to create list:
<ul>
<li><a href="..." title="...">categoryname</a></li>
....
</ul>

Then assign to this list a set of css rules to make it look like you
wanted. (check http://css.maxdesign.com.au for examples what you can
achieve with css and lists)

It's better way than making it only with hyperlinks and br's. You can
change category list presentation without modification in html.
 
F

fiefie.niles

Thanks.
I just want to make sure, so to use .NET 2.0 I need Visual Studio 2005,
is that correct ?

Thanks.
 
R

Rob MacFadyen

Thanks.
I just want to make sure, so to use .NET 2.0 I need Visual Studio 2005,
is that correct ?

Thanks.

Yes... and no.

If you installed the .NET framework 2.0 redistributable you could program
ASP.NET 2.0 just using notepad. Not fun but very doable.

If you install the ASP.NET Express edition (free version) you can use the
new Visual Studio to do ASP.NET 2.0.

I doubt if VS2003 can be configured to work with the 2.0 framework. It would
require a whole bunch of investigation and settings tweaking... if
successful you still wont get any of the new IDE features... just compiling.
So... not really worth spending a day on and potentially messing up your
current development environment.

So... from a practical standpoint.... VS2005 = .NET 2.0. Worth the money...
but there are other implications (moving from 1.x to 2.0 is easy enough...
but it is not just a recompile... some code changes may be required).

Regards,

Rob
 

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,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top