Link to home
Start Free TrialLog in
Avatar of -cr-
-cr-

asked on

Setting last field of data table to be a hyperlink

I have the code below and need to make the last field a hyperlink to VeiwQuoteID.aspx

  Dim EMailLogDataStoredProcedure As String

        Select Case Request.QueryString("sp")
            Case "1"
                EMailLogDataStoredProcedure = "usr_sel_EMailLog_BrokerAdministrationEMailLogOutput"
            Case "2"
                EMailLogDataStoredProcedure = "usr_sel_EMailLog_BrokerAdministrationEMailLogOutput_BrandedPageOwnerEMailOutput"
            Case "3"
                EMailLogDataStoredProcedure = "usr_sel_EMailLog_BrokerAdministrationEMailLogOutput_ManagerEmployeeEMailOutput"
        End Select
        Dim dt As New DataTable
        'dt.Columns.Add("ID", GetType(Integer))
        dt.Columns.Add("Sender", GetType(String))
        dt.Columns.Add("Recipient", GetType(String))
        dt.Columns.Add("Subject", GetType(String))
        dt.Columns.Add("SentDate", GetType(DateTime))
        dt.Columns.Add("View", GetType(String))

        'Dim Crypter As New Encryption64
        Dim strBrokerEmail As String = Request.Cookies("BrokerEMailAddress").Value
        'MsgBox(strBrokerEmail, MsgBoxStyle.Information, "Broker Email")
        Dim strSP As String = EMailLogDataStoredProcedure
        Dim EMailLogDataConnString As String = ConfigurationManager.AppSettings("***")
        Dim EMailLogDataConn As New SqlConnection(EMailLogDataConnString)
        Dim SQLEMailLogDataCmd As New SqlCommand(strSP, EMailLogDataConn)
        Dim EMailLogData As SqlDataReader
        SQLEMailLogDataCmd.CommandType = CommandType.StoredProcedure
        SQLEMailLogDataCmd.Parameters.AddWithValue("@BrokerEMailAddress", strBrokerEmail)
        SQLEMailLogDataCmd.Parameters.AddWithValue("@StartDate", StartDate.Text)
        SQLEMailLogDataCmd.Parameters.AddWithValue("@EndDate", EndDate.Text)
        EMailLogDataConn.Open()
        EMailLogData = SQLEMailLogDataCmd.ExecuteReader
        While EMailLogData.Read
            dt.Rows.Add(New Object() {LCase(EMailLogData("Sender")), LCase(EMailLogData("Recipient")), LCase(EMailLogData("Subject")), LCase(EMailLogData("SentDate")), LCase(EMailLogData("QuoteID"))})
        End While

        If EMailLogData.HasRows = False Then
            lblNoResults.Visible = False
            lblNoResults.Text = "**Sorry there were no results for your query"
            lblNoResults.Visible = True
        End If
        If EMailLogData.HasRows = True Then
            lblNoResults.Visible = False
            Grid1.DataSource = dt
            Grid1.DataBind()
            Grid1.Visible = True
        End If
        SQLEMailLogDataCmd.Dispose()
        SQLEMailLogDataCmd = Nothing
        EMailLogData.Close()
        EMailLogData = Nothing
        EMailLogDataConn.Close()
        EMailLogDataConn.Dispose()
        EMailLogDataConn = Nothing
        EMailLogDataConnString = Nothing
Avatar of adam_pedley
adam_pedley

I imagine the reason you want to set the last column a hyperlink because you want to have the hyperlink in the GridView

Which project type are you using ASP.NET or Windows Application

if its ASP.NET in the markup you can go
            <asp:TemplateField>
        <ItemTemplate>
    <%# "<a href='viewQuoteID.aspx?ID=" & Eval("fieldname") & "'>" & Eval("otherfieldname") & "</a>" %>

        </ItemTemplate>
    </asp:TemplateField>

just a note that the # could be an = sign (i currently cant remember which one it is)

<asp
ASKER CERTIFIED SOLUTION
Avatar of adam_pedley
adam_pedley

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
'Try this


'Prøv denne her klasse som håndterer hyperlinks

Class Form34
    Inherits Form
   
    Private dt As DataTable = New DataTable
   
    Public Sub New()
        MyBase.New
        InitializeComponent
    End Sub
   
    Private Sub Form34_Load(ByVal sender As Object, ByVal e As EventArgs)
        dt.Columns.Add("id")
        dt.Columns.Add("link")
        dt.Rows.Add("1", "http://www.microsoft.com")
        dt.Rows.Add("2", "http://www.google.com")
        dt.AcceptChanges
        Me.dataGridView1.DataSource = dt
        Me.dataGridView1.Columns.RemoveAt(1)
        Dim dgvlc As DataGridViewLinkColumn = New DataGridViewLinkColumn
        dgvlc.DataPropertyName = "link"
        'bind to the correct data column
        dgvlc.HeaderText = "Link"
        dgvlc.Width = 260
        Me.dataGridView1.Columns.Add(dgvlc)
        AddHandler dataGridView1.CellContentClick, AddressOf Me.dataGridView1_CellContentClick
    End Sub
   
    Private Sub dataGridView1_CellContentClick(ByVal sender As Object, ByVal e As DataGridViewCellEventArgs)
        If (TypeOf Me.dataGridView1.Columns(e.ColumnIndex) Is DataGridViewLinkColumn) Then
            'do your stuff here
            Dim link As String = Me.dataGridView1(e.ColumnIndex, e.RowIndex).Value.ToString
            System.Diagnostics.Process.Start(link)
        End If
    End Sub
End Class

vbturbo
Avatar of -cr-

ASKER

Adam,
I ended up doing the same as metioned in the accepted solution prior to seeing your solution. Awarded points for that reason. Thanks for your help.