How do I have datagrid hyperlinks?

J

Jonathan

In the sample code below, how do I make the various text items in a datagrid
column have a clickable hyperlinks?

e.g. Ford Mustang

should be a link to www.mysite.com/mustang.htm


</head>

<%@ Page language="VB" Debug="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>

<script language="VB" runat="server">

Sub Page_Load(Sender as Object, E as EventArgs)

Dim oConn As OleDbConnection
Dim oComm As OleDbDataAdapter
Dim sConn As String
Dim sComm As String
Dim oDataSet As New DataSet

'Build the connection string
sConn = "Provider=Microsoft.Jet.OLEDB.4.0;"
sConn += "Data Source=D:\inetpub\www\mysite\myaccessdb.mdb;"
sConn += "Persist Security Info=False"

'Build the SQL string
sComm = "SELECT qryDataGrid01.* "
sComm += "FROM qryDataGrid01;"

'Create the connection and command objects
oConn = New OleDbConnection(sConn)
oComm = New OleDbDataAdapter(sComm, oConn)

'Fill the dataset with the results of the query
oComm.Fill(oDataSet, "qryDataGrid01")

'Set the grid source to the dataset and bind the data
oGrid.DataSource=oDataSet.Tables("qryDataGrid01").DefaultView
oGrid.DataBind()

End Sub
</script>


<asp:DataGrid runat="server" id="oGrid" BackColor="#eeeeee"
HorizontalAlign="Left">
<HeaderStyle Font-Bold="True"/>
<AlternatingItemStyle BackColor="White" />
</asp:datagrid>
 
M

Masudur

In the sample code below, how do I make the various text items in a datagrid
column have a clickable hyperlinks?

e.g. Ford Mustang

should be a link towww.mysite.com/mustang.htm

</head>

<%@ Page language="VB" Debug="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>

<script language="VB" runat="server">

Sub Page_Load(Sender as Object, E as EventArgs)

Dim oConn As OleDbConnection
Dim oComm As OleDbDataAdapter
Dim sConn As String
Dim sComm As String
Dim oDataSet As New DataSet

'Build the connection string
sConn = "Provider=Microsoft.Jet.OLEDB.4.0;"
sConn += "Data Source=D:\inetpub\www\mysite\myaccessdb.mdb;"
sConn += "Persist Security Info=False"

'Build the SQL string
sComm = "SELECT qryDataGrid01.* "
sComm += "FROM qryDataGrid01;"

'Create the connection and command objects
oConn = New OleDbConnection(sConn)
oComm = New OleDbDataAdapter(sComm, oConn)

'Fill the dataset with the results of the query
oComm.Fill(oDataSet, "qryDataGrid01")

'Set the grid source to the dataset and bind the data
oGrid.DataSource=oDataSet.Tables("qryDataGrid01").DefaultView
oGrid.DataBind()

End Sub
</script>

<asp:DataGrid runat="server" id="oGrid" BackColor="#eeeeee"
HorizontalAlign="Left">
<HeaderStyle Font-Bold="True"/>
<AlternatingItemStyle BackColor="White" />
</asp:datagrid>

Hi...

Add columns for your grid...
Edit the item template and make the items whatever you like

Thanks
Md. Masudur Rahman
www.munna.shatkotha.com
www.kaz.com.bd
 
G

gnewsgroup

In the sample code below, how do I make the various text items in a datagrid
column have a clickable hyperlinks?

e.g. Ford Mustang

should be a link towww.mysite.com/mustang.htm

</head>

<%@ Page language="VB" Debug="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>

<script language="VB" runat="server">

Sub Page_Load(Sender as Object, E as EventArgs)

Dim oConn As OleDbConnection
Dim oComm As OleDbDataAdapter
Dim sConn As String
Dim sComm As String
Dim oDataSet As New DataSet

'Build the connection string
sConn = "Provider=Microsoft.Jet.OLEDB.4.0;"
sConn += "Data Source=D:\inetpub\www\mysite\myaccessdb.mdb;"
sConn += "Persist Security Info=False"

'Build the SQL string
sComm = "SELECT qryDataGrid01.* "
sComm += "FROM qryDataGrid01;"

'Create the connection and command objects
oConn = New OleDbConnection(sConn)
oComm = New OleDbDataAdapter(sComm, oConn)

'Fill the dataset with the results of the query
oComm.Fill(oDataSet, "qryDataGrid01")

'Set the grid source to the dataset and bind the data
oGrid.DataSource=oDataSet.Tables("qryDataGrid01").DefaultView
oGrid.DataBind()

End Sub
</script>

<asp:DataGrid runat="server" id="oGrid" BackColor="#eeeeee"
HorizontalAlign="Left">
<HeaderStyle Font-Bold="True"/>
<AlternatingItemStyle BackColor="White" />
</asp:datagrid>

Just a reminder: there is a HyperLink field if you use GridView
(ASP.NET 2.0). But if you cannot use ASP.NET 2.0, that's another
story.
 
S

Steven Cheng

Hi Jonathan,

If you're using ASP.NET 2.0, you can use GridView instead of DataGrid
control since GridView is better.

As for adding hyperlink in DataGrid or GridView column, you can conside
either use the built-in LinkFied(column) or define a template column and
put your own html mark(include link) in it.

Here are some web articles that may help you:

#Hyperlink Columns in GridView Control
http://geekswithblogs.net/azamsharp/archive/2005/10/30/58551.aspx

http://geekswithblogs.net/azamsharp/archive/2006/09/18/91514.aspx

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top