vb.net <asp:gridview row open new page

first of all, i'm very new in asp.net, second, sorry for my english,

I have this .asp code written in vb.net, and I manage to display the gridview's data. I've also added below lines of code to make the entire row clickable.

Private Sub AutoPopulateGridView_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles AutoPopulateGridView.RowCreated
    If e.Row.RowType = DataControlRowType.DataRow Then
        e.Row.Attributes("onmouseover") = "this.style.cursor='pointer';this.style.color='#47B6D2';"
        e.Row.Attributes("onmouseout") = "this.style.textDecoration='none';this.style.color='black';"
        e.Row.ToolTip = "Click to view details"         
    End If
End Sub

what I want to do is, when user clicked on each row(s), I'll open a new page loaded with new data that passed by that row the user clicked. and I'm stuck here.

2 answers

  • answered 2018-09-23 05:48 mike

    All of what you want to do can be done with GridView Templates on your ASPx page.

    Instead of letting the GridView define the columns itself, define them with Templates where you can add controls within the grid view. When you bind your data to the grid view, the controls in each column get bound to your data set automagically. Below, you can see there is a Hyperlink column that uses the Data Table column my_value_database_column this value gets passed to the new page on the GET or querystring. (Passing values this way is an HTTP GET).

    <asp:GridView ID="AutoPopulateGridView" runat="server" AutoGenerateColumns="False">
              <asp:TemplateField HeaderText="My Linked Column">
                      <asp:HyperLink ID="HyperLink1" runat="server" href='MyNextPage.aspx?valueToPass=<%#Eval("my_value_database_column").ToString()%>'><%# Eval("column_name_with_text").ToString()%></asp:HyperLink>
              <asp:TemplateField HeaderText="boring column" ItemStyle-CssClass="myHoverClass">
                      <%# Eval("other_datatable_column_name").ToString()%>

    To get the value passed on your next page, in the codebehind (.cs file) retrieve the value from the querystring:

    public partial class MyNextPage : System.Web.UI.Page
        protected void Page_Load(object sender, EventArgs e)
            //first page hit
            if (!IsPostBack)
                Response.Write("THE VALUE PASSED WAS '" + Request.QueryString["valueToPass"] + "'");

    ALso, the styles can be added directly to the gridview template in the ASPx page as well, using css and the psudo-class :hover

    <style type="text/css">
            .myHoverClass {
            .myHoverClass:hover {
                cursor: pointer;
                color: #47B6D2;

  • answered 2018-09-23 08:15 rykamol

    This solution is little bit different than yours. But you can get idea from here

    Here the list of data are showed in table format and editable link also added here so that you will get to know how to pass data(actually item id) using a tag in html.

    Here is the code .............

        dim query
        Dim objConn, objRS, sqlString
        set objConn = Server.CreateObject("ADODB.Connection")
        objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("hospital.mdb")    
        set objRS = Server.CreateObject("ADODB.Recordset")
        sqlString ="select * from Test"
        objRS.Open sqlString, objConn
                <table class="table table-border table-hover table-striped">
                    <thead class="thead-dark">
                        <th>Test Name</th>
                        <th>Test Type</th>
                        <th>Unit Price</th>
                    <% Do Until objRs.EOF = True%>
                    <tr id="<%=objRS("iD")%>">
                        <td> <a href='editTest.asp?Id=<%=objRS("Id")%>'>Edit</a></td>