How do i setup Gridview hyperlink passing data to another page

Posted on 2011-10-22
Last Modified: 2012-05-12
Hi all im trying to set my page up so when i client on a item in a gridview box it used the user id to do a query and takes the infomation to another page , i understand i can use Gridview hyperlink to pass data to another page but i have never do this before can someone please help me here
Question by:awolarczuk
    LVL 1

    Expert Comment


    Sub Ta3meem()
            'Dim mycon As New SqlConnection(SqlConn)
            'Dim adp As New SqlDataAdapter("select top 15 Title from tbl_News", mycon)
            'Dim ds As New Data.DataSet
            'GvTa3meem.DataSource = ds.Tables(0)
            Dim mylist As New List(Of String)
            Dim sql As String = "SELECT * from ActiveAdvertises" '"select Top 15 Title,id from tbl_News order by ID desc"
            Dim ds As DataSet = New DataSet
            ds = Selectsql(sql, SqlConn)
            If ds.Tables(0).Rows.Count > 0 Then
                For n As Integer = 0 To ds.Tables(0).Rows.Count - 1
                GvTa3meem.DataSource = mylist
                For i As Integer = 0 To GvTa3meem.Rows.Count - 1
                    Dim STRID As String = GvTa3meem.Rows(i).Cells(0).Text
                    Dim htmlA As New HtmlAnchor With {.InnerHtml = STRID, .HRef = "Ta3meemContent.aspx?ID=" & ds.Tables(0).Rows(i).Item("ID") & ""}
                    'htmlA.Style.Add("text-decoration", "underline")
                    'GvTa3meem.Rows(i).Cells(0).Attributes.Add("onclick", "'Ta3meemContent.aspx?ID=" & ds.Tables(0).Rows(i).Item("ID") & "','NewDetails','width=500,height=300');")
                    'GvTa3meem.Rows(i).Style.Add("cursor", "Hand")
                GvTa3meem.DataSource = Nothing
            End If
        End Sub

    Open in new window


    Author Comment

    Hi thanks for the code but could you please explaine it
    LVL 10

    Accepted Solution

    So I believe you the user to be redirected to another page when they select a row and their data exists on a table?

    see this link to setup the event that handles a gridview click without select command

    it will look something  like this:
    public sub PeopleGridView_RowDataBound(object as  sender, GridViewRowEventArgs as  e)
            if  e.Row.RowType = DataControlRowType.DataRow then
              '  e.Row.Attributes["onmouseover"] = "'hand';'underline';";
              '  e.Row.Attributes["onmouseout"] = "'none';";

              '  e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(this.PeopleGridView, "Select$" + e.Row.RowIndex);

            ' find a value of the textbox on the row they user slected
              dim t as textbox    
              t = GridView1.FooterRow.FindControl("txtData") as TextBox

           if t <> "" then
     ' ------------------------------------------------------------------

            ' GET data if it exists




                ' Dim MyDropDown As DropDownList

                ' Dim myArray As New ArrayList()

                Dim dataReader As SqlDataReader

                Dim x As Integer = 0

                Dim sqlConnection As String


                TC_ID = Session("SessionTC_ID")

                '  MyDropDown = DropDownList1



                Using sqlConn As New SqlConnection

                    sqlConnection = "Data Source=xx.xx.xx.xx;Initial Catalog=sddasdas;Trusted_connection=true;"

                    sqlConn.ConnectionString = sqlConnection

                    Dim SQLstring As String = "SELECT distinct(time_sent_range) FROM campaign WHERE TC_ID = '" & TC_ID & "' and campaign_name = '" & DDL_val & "'"



                    Using command As New SqlCommand(SQLstring, sqlConn)

                        dataReader = command.ExecuteReader(System.Data.CommandBehavior.CloseConnection)

                        If dataReader.HasRows Then

                            Do While dataReader.Read()

                                Session("Data_found") = (dataReader("time_sent_range").ToString())



                        End If



                    End Using

                End Using


            Catch ex As Exception


            End Try

            end if

    ' data exists redirect

     if  Session("Data_found") <> "" then

    end if

    ' =========
    ' data doesnt exist
     if  Session("Data_found") = "" then

    end if

     end sub
    LVL 10

    Expert Comment

    its rough should give you an idea...should have attached the code...apologies...
    LVL 10

    Expert Comment

    oops its rough again
      Session("Data_found") = (dataReader("time_sent_range").ToString())

    should be;
      Session("Data_found") = dataReader("time_sent_range").ToString()

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
    In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now