Avatar of thomasm1948
thomasm1948Flag for United States of America

asked on 

Gridview highlight and then select the row in a new window

I have a question.  I have a gridview and I would like the end-users to hightlight the row and when it is clicked open a new window with all of the content.  For the most part I i know how to pass session vairables but I am not sure how I can do this is  gridview.  

So far all I have is the gridview that is able to get the data from my sql database
.NET ProgrammingASP.NETVisual Basic.NET

Avatar of undefined
Last Comment
thomasm1948
SOLUTION
Avatar of MijaeDjinn
MijaeDjinn
Flag of Canada image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of lakshmidurga
lakshmidurga

My Grid name is Grid1
Protected Sub Grid1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles Grid1.DataBound
        Try
            Session("custsuperid") = customers.SelectedValue
            For Each gr As GridViewRow In Grid1.Rows
                For Each tc As TableCell In gr.Cells
                    Dim lbluser As Label = CType(tc.FindControl("txt_userid"), Label)
                    lbluser.Attributes.Add("onclick", "javascript:ShowContent('" + lbluser.Text + "');")

                Next
            Next
            Session("viewing") = "yes"
        Catch ex As Exception
            ErrorMessage(ex.Message)
        End Try
    End Sub

Javascript function

 function ShowContent(param)
    {
      var accn=param;
      window.open("UserDetails.aspx?NAC=" + accn ,'AccountDescription','width=1080, height=650, menubar=no, resizable=no,scrollbars=yes');
     }
     
ASKER CERTIFIED SOLUTION
Avatar of lakshmidurga
lakshmidurga

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of thomasm1948
thomasm1948
Flag of United States of America image

ASKER

I cannot seem to get it to work.  Is there someone that help me

thank you once again for all of your help
Avatar of thomasm1948
thomasm1948
Flag of United States of America image

ASKER

Attached is my code:

I am getting an error message stating Conversion from string "test.aspx?querystring1=" to type 'Double' is not valid.

The column that I am selecting is datatype int.  It seems to work if I use varchar, but I need it to work with the ID
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <style type="text/css">
        .style3
        {
            width: 259px;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <asp:Label ID="Label1" runat="server" Text="Open Cases" Font-Bold="True" 
        Font-Names="Arial" Font-Size="Small"></asp:Label>
    <br />
    <br />
    <table id="table1" style="width:100%;" width="100%">
        <tr>
            <td id="tdLeft">
                &nbsp;</td>
            <td id="tdCenter" class="style3" align="center" style="text-align: center">
                <asp:GridView ID="GridView1" runat="server" HorizontalAlign="Center" 
                    Width="597px" Font-Names="Arial" Font-Size="Small">
                    <Columns>
                    <asp:TemplateField>
                    <ItemTemplate>
                    <asp:HyperLink ID="HyperLink1" runat="server" Text='<%# Eval("Case ID") %>'
                       NavigateUrl='<%# "test.aspx?querystring1=" + Eval("Case ID") %>'></asp:HyperLink>
                     </ItemTemplate>
                    
                    </asp:TemplateField>
                    
                    </Columns>
                    <SelectedRowStyle BackColor="#0066FF" />
                    <AlternatingRowStyle BackColor="Silver" />
              
                
                </asp:GridView>
            </td>
            <td id="tdRight">
                &nbsp;</td>
        </tr>
        </table>
    
    
    
 
 
</asp:Content>

Open in new window

Avatar of thomasm1948
thomasm1948
Flag of United States of America image

ASKER

OK well I got something to work, but I do not think it is the best way.  Also it is not highlighting the row it is putting a select hyperlink on the screen

Please review my code and let me know if there is another way

Thank you for all of your help


<%@ Page Title="" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="OpenCases.aspx.vb" Inherits="OpenCases" %>
 
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <style type="text/css">
        .style3
        {
            width: 259px;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <asp:Label ID="Label1" runat="server" Text="Open Cases" Font-Bold="True" 
        Font-Names="Arial" Font-Size="Small"></asp:Label>
    <br />
    <br />
    <table id="table1" style="width:100%;" width="100%">
        <tr>
            <td id="tdLeft">
                &nbsp;</td>
            <td id="tdCenter" class="style3" align="center" style="text-align: center">
                <asp:GridView ID="GridView1" runat="server" HorizontalAlign="Center" 
                    Width="597px" Font-Names="Arial" Font-Size="Small">
                    <Columns>
                    <asp:TemplateField>
                    <ItemTemplate>
                    <asp:HyperLink ID="Link" runat="server" ForeColor="Blue" Text='<%# Eval("Case ID") %>'>
                       </asp:HyperLink>
                     </ItemTemplate>
                    
                    </asp:TemplateField>
                    
                    </Columns>
                    <SelectedRowStyle BackColor="#0066FF" />
                    <AlternatingRowStyle BackColor="Silver" />
              
                
                </asp:GridView>
            </td>
            <td id="tdRight">
                &nbsp;</td>
        </tr>
        </table>
 
 
 
</asp:Content>
 
Code behind:
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim test As String
            Dim lnkMore As HyperLink = DirectCast(e.Row.FindControl("link"), HyperLink)
            test = lnkMore.Text
            
 
            lnkMore.Text = "Select"
            lnkMore.Attributes.Add _
            ("onclick", "window.open('test.aspx?pram1=" & test & _
             "',null, 'left=400, top=100, height=250, width= 250, status=no, resizable=no, scrollbars=no, _toolbar=no,location=no, menubar=no');void(0); ")
            lnkMore.Attributes.Add("onMouseOver", "this.style.cursor='hand'")
 
            
        End If

Open in new window

.NET Programming
.NET Programming

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

137K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo