473,386 Members | 1,610 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Creating Hyperlinks

used the following "classic ASP" approach to build a dynamic menu, but would
like to know the proper way to implement the same functionality using a .Net
technique (e.g., placing the code in the .cs file and dynamically building the
hyperlink controls). The controls need to appear within the same <TD>,
separated by two spaces

Thanks for your help
-----
<%@ Import Namespace="Microsoft.Practices.EnterpriseLibrary.D ata" %>
<%@ Import Namespace="Microsoft.Practices.EnterpriseLibrary.D ata.Sql" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Common" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="MenuSub.ascx.cs"
Inherits="SubMenu" %>
<table id="table1" cellSpacing="0" cellPadding="0" width="900" border="0">
<TR bgColor="#2a69b3">
<TD vAlign="middle" align="center" width="900" height="20">
<%
Database db = DatabaseFactory.CreateDatabase();
string sqlCommand = "pr_MenuSub_SELECT";
DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand);
db.AddInParameter(dbCommand, "MM_Description", DbType.String, "HR");

using (IDataReader dataReader = db.ExecuteReader(dbCommand))
{
while (dataReader.Read())
{
// Get the value of the Name column in the DbDataReader.
Response.Write("<a href=" +
dataReader["MS_Page"].ToString() + ">" + dataReader["MS_Description"].ToString()
+ "</href>");
Response.Write("&nbsp;&nbsp;");
}
}
%>
</TD>
</TR>
</table>


Feb 6 '06 #1
3 1582
Garth you can make use of a repeater.
Just embed a hyerplink control in it and Databind it.
Hope that helps
Patrick

"Garth Wells" <no****@nowhere.com> wrote in message
news:e8**************@TK2MSFTNGP14.phx.gbl...
used the following "classic ASP" approach to build a dynamic menu, but would like to know the proper way to implement the same functionality using a ..Net technique (e.g., placing the code in the .cs file and dynamically building the hyperlink controls). The controls need to appear within the same <TD>,
separated by two spaces

Thanks for your help
-----
<%@ Import Namespace="Microsoft.Practices.EnterpriseLibrary.D ata" %>
<%@ Import Namespace="Microsoft.Practices.EnterpriseLibrary.D ata.Sql" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Common" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="MenuSub.ascx.cs" Inherits="SubMenu" %>
<table id="table1" cellSpacing="0" cellPadding="0" width="900" border="0">
<TR bgColor="#2a69b3">
<TD vAlign="middle" align="center" width="900" height="20">
<%
Database db = DatabaseFactory.CreateDatabase();
string sqlCommand = "pr_MenuSub_SELECT";
DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand);
db.AddInParameter(dbCommand, "MM_Description", DbType.String, "HR");
using (IDataReader dataReader = db.ExecuteReader(dbCommand))
{
while (dataReader.Read())
{
// Get the value of the Name column in the DbDataReader. Response.Write("<a href=" +
dataReader["MS_Page"].ToString() + ">" + dataReader["MS_Description"].ToString() + "</href>");
Response.Write("&nbsp;&nbsp;");
}
}
%>
</TD>
</TR>
</table>

Feb 6 '06 #2
You could actually do this in several ways. The trick is to think
object-oriented. First, you'll need to place your databsae code within an
event. You can't just place it inline as you could in classic asp. Your best
bet is to place it in the Page_Load event of your MenuSub.ascx.cs file. You
can do a couple of different things here.

The easiest, is to create a Literal control at the location you want between
the td elements like so:
<TD vAlign="middle" align="center" width="900" height="20"><asp:Literal
id="myLinks" runat="server"/></TD>

Now, in the codebehind you'll need to ensure you have this declared as a
variable as so:

protected Literal myLinks;

You can create your while loop just like you do, except instead of
response.writing, concatenate it into a string. Once you're done with the
look you can then dump the string which now holds the concactenated link
strings right into the literal such as myLinks.Text = stringLinks;

Of course, you could do it by creating a new HtmlAnchor object during each
iteration, setting the values from the datareader, and then adding them as a
child control to the literal. That would be the more object oriented
approach and give you a bit more control later on if you want to tie
server-side events such as an onlclick event to them, but initially you
would just end up with using a bit more memory and slower response to create
each object in the list.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

"Garth Wells" <no****@nowhere.com> wrote in message
news:e8**************@TK2MSFTNGP14.phx.gbl...
used the following "classic ASP" approach to build a dynamic menu, but
would
like to know the proper way to implement the same functionality using a
.Net
technique (e.g., placing the code in the .cs file and dynamically building
the
hyperlink controls). The controls need to appear within the same <TD>,
separated by two spaces

Thanks for your help
-----
<%@ Import Namespace="Microsoft.Practices.EnterpriseLibrary.D ata" %>
<%@ Import Namespace="Microsoft.Practices.EnterpriseLibrary.D ata.Sql" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Common" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<%@ Control Language="C#" AutoEventWireup="true"
CodeFile="MenuSub.ascx.cs"
Inherits="SubMenu" %>
<table id="table1" cellSpacing="0" cellPadding="0" width="900" border="0">
<TR bgColor="#2a69b3">
<TD vAlign="middle" align="center" width="900" height="20">
<%
Database db = DatabaseFactory.CreateDatabase();
string sqlCommand = "pr_MenuSub_SELECT";
DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand);
db.AddInParameter(dbCommand, "MM_Description", DbType.String,
"HR");

using (IDataReader dataReader = db.ExecuteReader(dbCommand))
{
while (dataReader.Read())
{
// Get the value of the Name column in the
DbDataReader.
Response.Write("<a href=" +
dataReader["MS_Page"].ToString() + ">" +
dataReader["MS_Description"].ToString()
+ "</href>");
Response.Write("&nbsp;&nbsp;");
}
}
%>
</TD>
</TR>
</table>

Feb 6 '06 #3
For what you're describing, you would use a Repeater Control that is bound
to a DataTable. The Repeater Control repeats whatever HTML and data you put
into the Template.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Who is Mighty Abbott?
A twin turret scalawag.

"Garth Wells" <no****@nowhere.com> wrote in message
news:e8**************@TK2MSFTNGP14.phx.gbl...
used the following "classic ASP" approach to build a dynamic menu, but
would
like to know the proper way to implement the same functionality using a
.Net
technique (e.g., placing the code in the .cs file and dynamically building
the
hyperlink controls). The controls need to appear within the same <TD>,
separated by two spaces

Thanks for your help
-----
<%@ Import Namespace="Microsoft.Practices.EnterpriseLibrary.D ata" %>
<%@ Import Namespace="Microsoft.Practices.EnterpriseLibrary.D ata.Sql" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Common" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<%@ Control Language="C#" AutoEventWireup="true"
CodeFile="MenuSub.ascx.cs"
Inherits="SubMenu" %>
<table id="table1" cellSpacing="0" cellPadding="0" width="900" border="0">
<TR bgColor="#2a69b3">
<TD vAlign="middle" align="center" width="900" height="20">
<%
Database db = DatabaseFactory.CreateDatabase();
string sqlCommand = "pr_MenuSub_SELECT";
DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand);
db.AddInParameter(dbCommand, "MM_Description", DbType.String,
"HR");

using (IDataReader dataReader = db.ExecuteReader(dbCommand))
{
while (dataReader.Read())
{
// Get the value of the Name column in the
DbDataReader.
Response.Write("<a href=" +
dataReader["MS_Page"].ToString() + ">" +
dataReader["MS_Description"].ToString()
+ "</href>");
Response.Write("&nbsp;&nbsp;");
}
}
%>
</TD>
</TR>
</table>

Feb 6 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Colleyville Alan | last post by:
I have an application that has an Access table that stores the locations of slides in a Powerpoint file. This used to work fine when there were about 4 files and 200 slides. The database would...
0
by: Tim | last post by:
Access 97: I have a table with a hyperlink field that I display on a form. I can click on the form field and the hyperlink activates correctly. However, if I try to activate the hyperlink using VB...
3
by: Joe | last post by:
I have a table with hundreds of hyperlinks in one field (defined as a hyperlink field) and a short name for each link in another field. I can successfully export a report to HTML with the short...
1
by: Dixie | last post by:
I wish to add some fields to an existing table in code. I am using the following code from rkc. CurrentDb.Execute ("ALTER TABLE MyTable ADD MyNewField Text 25") This works , but I need to also set...
4
by: Seefor | last post by:
Hi, I want my text hyperlinks to have a dotted border underneath, so I did this which works fine: a, a:link, a:visited, a:hover, a:active { color: #000; text-decoration: none;
1
by: Robin | last post by:
Hello! I'm having trouble with links and hyperlinks in MS Access 2003 - any help would be great! Question 1! The "insert hyperlink" icon opens a browser window, allows the user to browse...
3
by: simon | last post by:
Hello, i'm looking to create an aspx page that is basically a FAQ page i'm not sure if this can be done, but would love some help with suggestions of how to do it another way if this is not...
1
by: Janna | last post by:
Hello tech savvy gurus! I hope someone can help me! THE PROBLEM: "Cannot open specified file" when I click on a hyperlink in an Access database when it is located on our server. THE...
1
by: mforema | last post by:
Hi Everybody, I have an Access table with a field filled with outdated hyperlinks. I also have an excel spreadsheet that is the master list for these hyperlinks. The spreadsheet will be updated...
3
by: prinsipe | last post by:
Hi all, what i'm doing is showing/hiding hyperlinks depending on the hyperlink clicked. it is partially working. when i call step1, all hyperlinks are hidden. but then i call step2, single and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.