• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 262
  • Last Modified:

How do i setup Gridview hyperlink passing data to another page

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
0
awolarczuk
Asked:
awolarczuk
  • 3
1 Solution
 
myaspnetCommented:

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
        'adp.Fill(ds)
        'GvTa3meem.DataSource = ds.Tables(0)
        'GvTa3meem.DataBind()
        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
                mylist.Add(ds.Tables(0).Rows(n)("Title"))
            Next
            GvTa3meem.DataSource = mylist
            GvTa3meem.DataBind()
            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") & ""}
                GvTa3meem.Rows(i).Cells(0).Controls.Clear()
                'htmlA.Style.Add("text-decoration", "underline")
                GvTa3meem.Rows(i).Cells(0).Controls.Add(htmlA)
                'GvTa3meem.Rows(i).Cells(0).Attributes.Add("onclick", "javascript:window.open('Ta3meemContent.aspx?ID=" & ds.Tables(0).Rows(i).Item("ID") & "','NewDetails','width=500,height=300');")
                'GvTa3meem.Rows(i).Style.Add("cursor", "Hand")
            Next
        Else
            GvTa3meem.DataSource = Nothing
        End If
    End Sub

Open in new window

0
 
awolarczukAuthor Commented:
Hi thanks for the code but could you please explaine it
0
 
GlobaLevelCommented:
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
http://www.geekzilla.co.uk/view9FC28EE6-ACB0-4F51-BFE4-38B0B10134D5.htm

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"] = "this.style.cursor='hand';this.style.textDecoration='underline';";
          '  e.Row.Attributes["onmouseout"] = "this.style.textDecoration='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

        '

       

        Try

            ' 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 & "'"

         

                sqlConn.Open()

                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())

                        Loop

                       

                    End If

                    dataReader.Close()

                    sqlConn.Close()

                End Using

            End Using

           

        Catch ex As Exception

           

        End Try

        end if



'==============
' data exists redirect

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

response.redirect("dat_exists.aspx")
end if


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

response.redirect("dat_DOESNT_exists.aspx")
end if


 end sub
0
 
GlobaLevelCommented:
its rough should give you an idea...should have attached the code...apologies...
0
 
GlobaLevelCommented:
oops its rough again
this
  Session("Data_found") = (dataReader("time_sent_range").ToString())

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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now