Home All Groups Group Topic Archive Search About

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

Author
9 Sep 2006 3:55 PM
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

Author
9 Sep 2006 8:10 PM
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
Author
10 Sep 2006 10:32 AM
Przemek Ptasznik
fiefie.ni***@gmail.com 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.

--
PP
Author
9 Sep 2006 8:51 PM
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


<fiefie.ni***@gmail.com> wrote in message
Show quote
news:1157817306.920156.27880@i42g2000cwa.googlegroups.com...
>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
>
Author
9 Sep 2006 10:17 PM
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.

Rob MacFadyen wrote:
Show quote
> 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
>
>
> <fiefie.ni***@gmail.com> wrote in message
> news:1157817306.920156.27880@i42g2000cwa.googlegroups.com...
> >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
> >
Author
9 Sep 2006 10:18 PM
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.

Rob MacFadyen wrote:
Show quote
> 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
>
>
> <fiefie.ni***@gmail.com> wrote in message
> news:1157817306.920156.27880@i42g2000cwa.googlegroups.com...
> >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
> >
Author
10 Sep 2006 3:36 AM
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


<fiefie.ni***@gmail.com> wrote in message
Show quote
news:1157840285.783818.271850@i3g2000cwc.googlegroups.com...
> 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.
>
> Rob MacFadyen wrote:
>> 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
>>
>>
>> <fiefie.ni***@gmail.com> wrote in message
>> news:1157817306.920156.27880@i42g2000cwa.googlegroups.com...
>> >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
>> >
>
Author
10 Sep 2006 3:50 PM
fiefie.niles
Thanks.
I just want to make sure, so to use .NET 2.0 I need Visual Studio 2005,
is that correct ?

Thanks.


Rob MacFadyen wrote:
Show quote
> 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
>
>
> <fiefie.ni***@gmail.com> wrote in message
> news:1157840285.783818.271850@i3g2000cwc.googlegroups.com...
> > 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.
> >
> > Rob MacFadyen wrote:
> >> 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
> >>
> >>
> >> <fiefie.ni***@gmail.com> wrote in message
> >> news:1157817306.920156.27880@i42g2000cwa.googlegroups.com...
> >> >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
> >> >
> >

AddThis Social Bookmark Button