Hyperlink problem

K

Ken Cox [Microsoft MVP]

Hi Andrew,

It sounds like you are binding to the wrong field or concatenating
something. Perhaps you could post the troublesome code? Here's some example
code:

Dim dt As DataTable
Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
If Not IsPostBack Then
DataGrid1.DataSource = CreateDataSource()
DataGrid1.DataBind()
End If
End Sub



Function CreateDataSource() As ICollection

' Create sample data for the DataList control.
dt = New DataTable
Dim dr As DataRow

' Define the columns of the table.
dt.Columns.Add(New DataColumn("Item", GetType(String)))
dt.Columns.Add(New DataColumn("Qty", GetType(Int32)))
dt.Columns.Add(New DataColumn("Price", GetType(Double)))

' Populate the table with sample values.
Dim i As Integer

For i = 0 To 8
dr = dt.NewRow()
dr(0) = "http://mydomain/Item" & i.ToString & ".aspx"
dr(1) = i * 2
dr(2) = 1.23 * (i + 1)
dt.Rows.Add(dr)
Next i

Dim dv As DataView = New DataView(dt)
Return dv
End Function


<form id="Form1" method="post" runat="server">
<asp:DataGrid id="DataGrid1" runat="server">
<Columns>
<asp:HyperLinkColumn Target="_blank" DataNavigateUrlField="Item"
DataTextField="Price" HeaderText="Link"></asp:HyperLinkColumn>
</Columns>
</asp:DataGrid>
<P>&nbsp;</P>
<P>
<asp:Label id="Label1" runat="server">Label</asp:Label></P>
</form>

Ken
Microsoft MVP [ASP.NET]
Toronto
 
A

andrew sargent

OK, here goes:


<%@ Page Language="VB" %>
<script runat="server">

Sub Page_Load (sender As Object, e As EventArgs)

dgNews.Datasource = GetNews()
dgNews.DataBind()

End Sub


Function GetNews() As System.Data.IDataReader
Dim connectionString As String =
"Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data
Source=xxxxxxxxxxxxxxxxxxxxxx"
Dim dbConnection As System.Data.IDbConnection = New
System.Data.OleDb.OleDbConnection(connectionString)

Dim queryString As String = "SELECT [news].[Title],
[news].[Text], [news]., [news].[Date] FROM [news]" Dim db...y help you can give Andrew [/QUOTE] [/QUOTE]
 
K

Ken Cox [Microsoft MVP]

Hi Andrew,

Hi had to rejig your code to use the Nwind database. You seem to be using
some strange interfaces which I changed. Not sure what's the reason.

Try this to see how you do?

Ken
Microsoft MVP [ASP.NET]


<%@ Page Language="VB" %>
<%@ import namespace="system.data" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<script runat="server">
Sub Page_Load(ByVal sender As Object, _
ByVal e As System.EventArgs)
If Not IsPostBack Then
dgNews.DataSource = GetNews()
dgNews.DataBind()
End If
End Sub

Function GetNews() As _
System.Data.OleDb.OleDbDataReader
Dim connectionString As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
Server.MapPath("data/nwind.mdb")
Dim dbConnection As System.Data.OleDb.OleDbConnection = _
New System.Data.OleDb.OleDbConnection(connectionString)
Dim queryString As String = "SELECT * from employees "
' Dim queryString As String = "SELECT [news].[Title],
[news].[Text], [news]., [news].[Date] FROM [news] " Dim d...asp:datagrid> </div> </form> </body> </html>
 
A

andrew sargent

The code was generated with webmatrix which may explain why it differs from
your code.

I seem to have the same problem with this codde too. so i am not sure what
is going wrong!


Ken Cox said:
Hi Andrew,

Hi had to rejig your code to use the Nwind database. You seem to be using
some strange interfaces which I changed. Not sure what's the reason.

Try this to see how you do?

Ken
Microsoft MVP [ASP.NET]


<%@ Page Language="VB" %>
<%@ import namespace="system.data" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<script runat="server">
Sub Page_Load(ByVal sender As Object, _
ByVal e As System.EventArgs)
If Not IsPostBack Then
dgNews.DataSource = GetNews()
dgNews.DataBind()
End If
End Sub

Function GetNews() As _
System.Data.OleDb.OleDbDataReader
Dim connectionString As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
Server.MapPath("data/nwind.mdb")
Dim dbConnection As System.Data.OleDb.OleDbConnection = _
New System.Data.OleDb.OleDbConnection(connectionString)
Dim queryString As String = "SELECT * from employees "
' Dim queryString As String = "SELECT [news].[Title],
[news].[Text], [news]., [news].[Date] FROM [news] " Dim d...style> <itemstyle forecolor="#4A3C8C"[/QUOTE]
 
A

andrew sargent

OK, I have figured out where i was going wrong. The data type in the
database was set to Hyperlink.
I changed it to Text and...bob's your mother's brother ;-)

Andrew


andrew sargent said:
The code was generated with webmatrix which may explain why it differs from
your code.

I seem to have the same problem with this codde too. so i am not sure what
is going wrong!


Ken Cox said:
Hi Andrew,

Hi had to rejig your code to use the Nwind database. You seem to be using
some strange interfaces which I changed. Not sure what's the reason.

Try this to see how you do?

Ken
Microsoft MVP [ASP.NET]


<%@ Page Language="VB" %>
<%@ import namespace="system.data" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<script runat="server">
Sub Page_Load(ByVal sender As Object, _
ByVal e As System.EventArgs)
If Not IsPostBack Then
dgNews.DataSource = GetNews()
dgNews.DataBind()
End If
End Sub

Function GetNews() As _
System.Data.OleDb.OleDbDataReader
Dim connectionString As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
Server.MapPath("data/nwind.mdb")
Dim dbConnection As System.Data.OleDb.OleDbConnection = _
New System.Data.OleDb.OleDbConnection(connectionString)
Dim queryString As String = "SELECT * from employees "
' Dim queryString As String = "SELECT [news].[Title],
[news].[Text], [news]., [news].[Date] FROM [news] " Dim d...iv> </form> </body> </html> [/QUOTE] [/QUOTE]
 
K

Ken Cox [Microsoft MVP]

Thanks for reporting back.

That's another weird one for someone else to find in a Google search some
day!
 

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

Similar Threads


Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top