|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to put a list of items with hyperlinks under a label ?..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>") LoopEnd If 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>") LoopEnd If fiefie.ni***@gmail.com napisał(a):
> I can use Response.write like in the following codes, but is there a Try to think of what you want to do: put _list_ of categories to > better way to do it ? > 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 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 > 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 > > 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 > > 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 >> > > 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 > >> > > > |
|||||||||||||||||||||||