Click here to Skip to main content
15,881,898 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone. I'm new to asp.net 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:


XML
<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}%'">
    <FilterParameters>
    <asp:ControlParameter Name="reportName" ControlID="txtSearch" PropertyName="Text" />
    <asp:ControlParameter Name="siteLocation" ControlID="txtSearch" PropertyName="Text" />
    </FilterParameters>
</asp:AccessDataSource>


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

XML
<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"
    >
    <Columns>
    <asp:ButtonField CommandName= "Select" Visible= "False" />
        <asp:TemplateField HeaderText="Report Name" SortExpression="reportName">
        <ItemStyle Width="200px" HorizontalAlign="Left" />
        <ItemTemplate>
            <asp:Label ID="lblReportName" Text='<%# HighlightText(Eval("Report Name")) %>'
                runat="server" />
        </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Site Location" SortExpression="siteLocation">
        <ItemStyle Width="120px" HorizontalAlign="Left" />
        <ItemTemplate>
            <asp:Label ID="lblSiteLocation" Text='<%# HighlightText(Eval("Site Location")) %>'
            runat="server" />
        </ItemTemplate>
    </asp:TemplateField>
      </Columns>
      <HeaderStyle         BackColor="#333399" ForeColor="White" Font-Bold="True" />
      <RowStyle            BackColor="#CCCCCC" />
      <AlternatingRowStyle BackColor="White" />
      <PagerStyle          BackColor="#333399" ForeColor="White" HorizontalAlign="Center" />
      <SelectedRowStyle BackColor="lightcyan" />
  </asp:GridView>


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

VB
Protected Overrides Sub Render(ByVal writer As _
                                   System.Web.UI.HtmlTextWriter)
        For Each row As GridViewRow In myGridView.Rows
            If row.RowType = DataControlRowType.DataRow Then
                row.Attributes("onmouseover") = _
                  "this.originalstyle=this.style.backgroundColor; this.style.cursor='hand'; this.style.backgroundColor='LightCyan'"
                row.Attributes("onmouseout") = _
                  "this.style.backgroundColor=this.originalstyle"


                ' 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
        Next
        MyBase.Render(writer)
    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...
Posted

1 solution


$(document).ready(function () {

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

})

})
/script&gt;</code>
 
Share this answer
 
Comments
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