Grid view with links.

Not sure what its called to search google....

Page 1 of 1

4 Replies - 1765 Views - Last Post: 02 August 2010 - 07:56 PM Rate Topic: -----

#1 crzyone9584  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 201
  • Joined: 22-April 08

Grid view with links.

Posted 02 August 2010 - 02:01 PM

I'm trying to add a link to a column in my gridview to load another page/view that will display information about things that will be pulled from a database. Here is everything i have so far.

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim con As New SqlConnection
        Dim reader As SqlDataReader

        con.ConnectionString = "my connectionstring"
        Dim strSql As String
        Dim SQLComm As New SqlCommand


        'OPEN DB CONNECTION   
        con.Open()

        strSql = "SELECT * FROM venatio_company"
        SQLComm = New SqlCommand(strSql, con)
        reader = SQLComm.ExecuteReader()
        companyview.DataSource = reader
        companyview.DataBind()

        reader.Close()
        con.Close()
    End Sub


Along with the layout.

    <asp:GridView ID="companyview" AutoGenerateColumns="False" runat="server">
    <Columns>
             <asp:BoundField HeaderText="Company Name" DataField="compname" />
             <asp:BoundField HeaderText="Role" DataField="role" />                 
             <asp:BoundField DataField="founded" HeaderText="Founded On" />
    </Columns>
    </asp:GridView>


How would i make the boundfiled with company name being diplayed into a link like this php page i have

<a href="game.php?id=<?php echo $result['id']?>


What im trying to do is have a multiview control have two different views. One with my gridview and one with labels to display the data from the sql server. I hope I've explained enough for you guys to understand.

Is This A Good Question/Topic? 0
  • +

Replies To: Grid view with links.

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Grid view with links.

Posted 02 August 2010 - 04:52 PM

Instead of using a BoundField for the company name column, use a HyperLinkField.
Was This Post Helpful? 0
  • +
  • -

#3 crzyone9584  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 201
  • Joined: 22-April 08

Re: Grid view with links.

Posted 02 August 2010 - 06:11 PM

View PostJayman, on 02 August 2010 - 03:52 PM, said:

Instead of using a BoundField for the company name column, use a HyperLinkField.


Ok but how would i make it go from view1 to view2 and load. With php you have the "GET" command that will fetch the data of the id that is thrown into it. How would i go about doing that in asp.net?
Was This Post Helpful? 0
  • +
  • -

#4 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Grid view with links.

Posted 02 August 2010 - 07:28 PM

Use the NavigateUrl property of the HyperlinkField to point to the other page and then add the ID as a Query String added to the end of the URL. When the new page loads, read the value from the Request.QueryString property and then query the database for the data to be displayed on that page.

On the second page you will just query the database using a SELECT statement with a WHERE condition.

Example GridView:
<asp:GridView ID="companyview" AutoGenerateColumns="False" runat="server">
<Columns>
         <asp:HyperLinkField Text="Details.." HeaderText="More Info" target="_blank" DataNavigateUrlFormatString="~/CompanyDetails.aspx?id={0}" DataTextField="companId" />
         <asp:BoundField HeaderText="Company Name" DataField="compname" />
         <asp:BoundField HeaderText="Role" DataField="role" />                 
         <asp:BoundField DataField="founded" HeaderText="Founded On" />
</Columns>
</asp:GridView>



Load event on CompanyDetails.aspx:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim con As New SqlConnection
    Dim reader As SqlDataReader
    'Get the ID from the Query String
    Dim companyId As String = Request.QueryString("compId")

    con.ConnectionString = "my connectionstring"
    Dim strSql As String
    Dim SQLComm As New SqlCommand


    'OPEN DB CONNECTION   
    con.Open()

    strSql = "SELECT * FROM venatio_company where compId = " & companyId
    SQLComm = New SqlCommand(strSql, con)
    reader = SQLComm.ExecuteReader()
    companyDetail.DataSource = reader
    companyDetail.DataBind()

    reader.Close()
    con.Close()
End Sub



Anyway, I think you will get the idea.
Was This Post Helpful? 0
  • +
  • -

#5 crzyone9584  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 201
  • Joined: 22-April 08

Re: Grid view with links.

Posted 02 August 2010 - 07:56 PM

Thanks for the help. Now I'll just have to figure out how to use it with the multiview control. I'm trying to keep pages down for its just a tad bit nicer looking to me and saves you from editing multiple files.

Thanks for the help.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1