Click here to Skip to main content
15,920,603 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone. I'm new to and I'm having problem extracting the content of a cell when a user click on a particular row in my gridview.
Have try all solutions I have found on the net, but I still can't figure it out.
I'm using AccessDataSource. And it select Report Name and Site Location from my table report. Below is my AccessDataSource code:

<asp:AccessDataSource ID="AccessDataSource2" runat="server" DataFile="~/App_Data/VirtualLibrary.mdb"
    SelectCommand="SELECT [reportName] AS [Report Name], [siteLocation] AS [Site Location] FROM [tblReport]" FilterExpression="[Report Name] like '%{0}%' OR [Site Location] Like '%{1}%'">
    <asp:ControlParameter Name="reportName" ControlID="txtSearch" PropertyName="Text" />
    <asp:ControlParameter Name="siteLocation" ControlID="txtSearch" PropertyName="Text" />

My Gridview display 2 columns, Report Name and Site Location. I have also a hidden Select button:

<asp:GridView ID="myGridView" DataSourceID="AccessDataSource2" runat="server" DataKeyNames = "Report Name"
    AutoGenerateColumns = "False"
    AllowPaging  = "True"
    AllowSorting = "True"
    CellPadding  = "4"
    ForeColor    = "#333333"
    GridLines="None" Width="433px"
    <asp:ButtonField CommandName= "Select" Visible= "False" />
        <asp:TemplateField HeaderText="Report Name" SortExpression="reportName">
        <ItemStyle Width="200px" HorizontalAlign="Left" />
            <asp:Label ID="lblReportName" Text='<%# HighlightText(Eval("Report Name")) %>'
                runat="server" />
    <asp:TemplateField HeaderText="Site Location" SortExpression="siteLocation">
        <ItemStyle Width="120px" HorizontalAlign="Left" />
            <asp:Label ID="lblSiteLocation" Text='<%# HighlightText(Eval("Site Location")) %>'
            runat="server" />
      <HeaderStyle         BackColor="#333399" ForeColor="White" Font-Bold="True" />
      <RowStyle            BackColor="#CCCCCC" />
      <AlternatingRowStyle BackColor="White" />
      <PagerStyle          BackColor="#333399" ForeColor="White" HorizontalAlign="Center" />
      <SelectedRowStyle BackColor="lightcyan" />

I have a function in my aspx.vb file which highlight rows when mouse is over:

Protected Overrides Sub Render(ByVal writer As _
        For Each row As GridViewRow In myGridView.Rows
            If row.RowType = DataControlRowType.DataRow Then
                row.Attributes("onmouseover") = _
                row.Attributes("onmouseout") = _

                ' Set the last parameter to True
                ' to register for event validation.
                row.Attributes("onclick") = ClientScript.GetPostBackEventReference(myGridView, "Select$" & row.DataItemIndex, True)
                row.ToolTip = "Click click to select row "
            End If
    End Sub

And some function which will allow me to search for a report and then it will highlight everywhere in my gridview where my search text occur. Have got this on the net:cool:

But problem occur when i want to copy the content of a cell in the Report Name column when a user click on a row in my gridview. Have got a lot of solutions on the net, but none seems to work for me.

Is there something I have write wrong, or something that I need to add. Plz help me...

1 solution

$(document).ready(function () {

$('#GridView1 tr').click(function () {
var text = $(this).find("td").eq(1).html();
window.clipboardData.setData("Text", text);


Share this answer
JDanBankai 25-Oct-10 1:07am    
Hello, thanks for your reply. I'm coding my pages as apsx pages. Have paste your code in mine and I'm having error message 'Attribute mode is not a valid attribute of element Script '

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900